1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "apps/custom_launcher_page_contents.h"
9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
11 #include "content/public/browser/render_view_host.h"
12 #include "content/public/browser/site_instance.h"
13 #include "content/public/browser/web_contents.h"
14 #include "content/public/common/renderer_preferences.h"
15 #include "extensions/browser/app_window/app_delegate.h"
16 #include "extensions/browser/app_window/app_web_contents_helper.h"
17 #include "extensions/browser/view_type_utils.h"
18 #include "extensions/common/extension_messages.h"
22 CustomLauncherPageContents::CustomLauncherPageContents(
23 scoped_ptr
<extensions::AppDelegate
> app_delegate
,
24 const std::string
& extension_id
)
25 : app_delegate_(app_delegate
.Pass()), extension_id_(extension_id
) {
28 CustomLauncherPageContents::~CustomLauncherPageContents() {
31 void CustomLauncherPageContents::Initialize(content::BrowserContext
* context
,
34 content::WebContents::Create(content::WebContents::CreateParams(
35 context
, content::SiteInstance::CreateForURL(context
, url
))));
37 web_contents_
->GetMutableRendererPrefs()
38 ->browser_handles_all_top_level_requests
= true;
39 web_contents_
->GetRenderViewHost()->SyncRendererPrefs();
41 helper_
.reset(new extensions::AppWebContentsHelper(
42 context
, extension_id_
, web_contents_
.get(), app_delegate_
.get()));
43 web_contents_
->SetDelegate(this);
45 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_LAUNCHER_PAGE
);
47 // This observer will activate the extension when it is navigated to, which
48 // allows Dispatcher to give it the proper context and makes it behave like an
50 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
53 web_contents_
->GetController().LoadURL(url
,
55 ui::PAGE_TRANSITION_AUTO_TOPLEVEL
,
59 content::WebContents
* CustomLauncherPageContents::OpenURLFromTab(
60 content::WebContents
* source
,
61 const content::OpenURLParams
& params
) {
62 DCHECK_EQ(web_contents_
.get(), source
);
63 return helper_
->OpenURLFromTab(params
);
66 void CustomLauncherPageContents::AddNewContents(
67 content::WebContents
* source
,
68 content::WebContents
* new_contents
,
69 WindowOpenDisposition disposition
,
70 const gfx::Rect
& initial_rect
,
73 app_delegate_
->AddNewContents(new_contents
->GetBrowserContext(),
81 bool CustomLauncherPageContents::IsPopupOrPanel(
82 const content::WebContents
* source
) const {
86 bool CustomLauncherPageContents::ShouldSuppressDialogs(
87 content::WebContents
* source
) {
91 bool CustomLauncherPageContents::PreHandleGestureEvent(
92 content::WebContents
* source
,
93 const blink::WebGestureEvent
& event
) {
94 return extensions::AppWebContentsHelper::ShouldSuppressGestureEvent(event
);
97 content::ColorChooser
* CustomLauncherPageContents::OpenColorChooser(
98 content::WebContents
* web_contents
,
99 SkColor initial_color
,
100 const std::vector
<content::ColorSuggestion
>& suggestionss
) {
101 return app_delegate_
->ShowColorChooser(web_contents
, initial_color
);
104 void CustomLauncherPageContents::RunFileChooser(
105 content::WebContents
* tab
,
106 const content::FileChooserParams
& params
) {
107 app_delegate_
->RunFileChooser(tab
, params
);
110 void CustomLauncherPageContents::RequestToLockMouse(
111 content::WebContents
* web_contents
,
113 bool last_unlocked_by_target
) {
114 DCHECK_EQ(web_contents_
.get(), web_contents
);
115 helper_
->RequestToLockMouse();
118 void CustomLauncherPageContents::RequestMediaAccessPermission(
119 content::WebContents
* web_contents
,
120 const content::MediaStreamRequest
& request
,
121 const content::MediaResponseCallback
& callback
) {
122 DCHECK_EQ(web_contents_
.get(), web_contents
);
123 helper_
->RequestMediaAccessPermission(request
, callback
);
126 bool CustomLauncherPageContents::CheckMediaAccessPermission(
127 content::WebContents
* web_contents
,
128 const GURL
& security_origin
,
129 content::MediaStreamType type
) {
130 DCHECK_EQ(web_contents_
.get(), web_contents
);
131 return helper_
->CheckMediaAccessPermission(security_origin
, type
);