Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / apps / custom_launcher_page_contents.cc
blob8888993aac5c39e380dc2df0ecc7ff1d34ae93ab
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"
7 #include <string>
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"
20 namespace apps {
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,
32 const GURL& url) {
33 web_contents_.reset(
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
49 // extension.
50 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
51 web_contents());
53 web_contents_->GetController().LoadURL(url,
54 content::Referrer(),
55 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
56 std::string());
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,
71 bool user_gesture,
72 bool* was_blocked) {
73 app_delegate_->AddNewContents(new_contents->GetBrowserContext(),
74 new_contents,
75 disposition,
76 initial_rect,
77 user_gesture,
78 was_blocked);
81 bool CustomLauncherPageContents::IsPopupOrPanel(
82 const content::WebContents* source) const {
83 return true;
86 bool CustomLauncherPageContents::ShouldSuppressDialogs(
87 content::WebContents* source) {
88 return true;
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,
112 bool user_gesture,
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);
134 } // namespace apps