OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "apps/custom_launcher_page_contents.h" | 5 #include "apps/custom_launcher_page_contents.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
| 9 #include "apps/app_delegate.h" |
| 10 #include "apps/app_web_contents_helper.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 12 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
11 #include "content/public/browser/browser_context.h" | 13 #include "content/public/browser/browser_context.h" |
12 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
13 #include "content/public/browser/site_instance.h" | 15 #include "content/public/browser/site_instance.h" |
14 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
15 #include "content/public/common/renderer_preferences.h" | 17 #include "content/public/common/renderer_preferences.h" |
16 #include "extensions/common/extension_messages.h" | 18 #include "extensions/common/extension_messages.h" |
17 | 19 |
18 namespace apps { | 20 namespace apps { |
19 | 21 |
20 CustomLauncherPageContents::CustomLauncherPageContents() { | 22 CustomLauncherPageContents::CustomLauncherPageContents( |
| 23 AppDelegate* app_delegate, |
| 24 const std::string& extension_id) |
| 25 : app_delegate_(app_delegate), extension_id_(extension_id) { |
21 } | 26 } |
22 | 27 |
23 CustomLauncherPageContents::~CustomLauncherPageContents() { | 28 CustomLauncherPageContents::~CustomLauncherPageContents() { |
24 } | 29 } |
25 | 30 |
26 void CustomLauncherPageContents::Initialize(content::BrowserContext* context, | 31 void CustomLauncherPageContents::Initialize(content::BrowserContext* context, |
27 const GURL& url) { | 32 const GURL& url) { |
28 extension_function_dispatcher_.reset( | 33 extension_function_dispatcher_.reset( |
29 new extensions::ExtensionFunctionDispatcher(context, this)); | 34 new extensions::ExtensionFunctionDispatcher(context, this)); |
30 | 35 |
31 web_contents_.reset( | 36 web_contents_.reset( |
32 content::WebContents::Create(content::WebContents::CreateParams( | 37 content::WebContents::Create(content::WebContents::CreateParams( |
33 context, content::SiteInstance::CreateForURL(context, url)))); | 38 context, content::SiteInstance::CreateForURL(context, url)))); |
34 | 39 |
35 Observe(web_contents()); | 40 Observe(web_contents()); |
36 web_contents_->GetMutableRendererPrefs() | 41 web_contents_->GetMutableRendererPrefs() |
37 ->browser_handles_all_top_level_requests = true; | 42 ->browser_handles_all_top_level_requests = true; |
38 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); | 43 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); |
39 | 44 |
| 45 helper_.reset(new AppWebContentsHelper( |
| 46 context, extension_id_, web_contents_.get(), app_delegate_.get())); |
| 47 web_contents_->SetDelegate(this); |
| 48 |
40 // This observer will activate the extension when it is navigated to, which | 49 // This observer will activate the extension when it is navigated to, which |
41 // allows Dispatcher to give it the proper context and makes it behave like an | 50 // allows Dispatcher to give it the proper context and makes it behave like an |
42 // extension. | 51 // extension. |
43 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | 52 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( |
44 web_contents()); | 53 web_contents()); |
45 | 54 |
46 web_contents_->GetController().LoadURL(url, | 55 web_contents_->GetController().LoadURL(url, |
47 content::Referrer(), | 56 content::Referrer(), |
48 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 57 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
49 std::string()); | 58 std::string()); |
50 } | 59 } |
51 | 60 |
| 61 content::WebContents* CustomLauncherPageContents::OpenURLFromTab( |
| 62 content::WebContents* source, |
| 63 const content::OpenURLParams& params) { |
| 64 DCHECK_EQ(web_contents_.get(), source); |
| 65 return helper_->OpenURLFromTab(params); |
| 66 } |
| 67 |
| 68 void CustomLauncherPageContents::AddNewContents( |
| 69 content::WebContents* source, |
| 70 content::WebContents* new_contents, |
| 71 WindowOpenDisposition disposition, |
| 72 const gfx::Rect& initial_pos, |
| 73 bool user_gesture, |
| 74 bool* was_blocked) { |
| 75 DCHECK(new_contents->GetBrowserContext() == helper_->browser_context()); |
| 76 app_delegate_->AddNewContents(new_contents->GetBrowserContext(), |
| 77 new_contents, |
| 78 disposition, |
| 79 initial_pos, |
| 80 user_gesture, |
| 81 was_blocked); |
| 82 } |
| 83 |
| 84 bool CustomLauncherPageContents::IsPopupOrPanel( |
| 85 const content::WebContents* source) const { |
| 86 return true; |
| 87 } |
| 88 |
| 89 bool CustomLauncherPageContents::ShouldSuppressDialogs() { |
| 90 return true; |
| 91 } |
| 92 |
| 93 bool CustomLauncherPageContents::PreHandleGestureEvent( |
| 94 content::WebContents* source, |
| 95 const blink::WebGestureEvent& event) { |
| 96 return AppWebContentsHelper::ShouldSuppressGestureEvent(event); |
| 97 } |
| 98 |
| 99 content::ColorChooser* CustomLauncherPageContents::OpenColorChooser( |
| 100 content::WebContents* web_contents, |
| 101 SkColor initial_color, |
| 102 const std::vector<content::ColorSuggestion>& suggestionss) { |
| 103 return app_delegate_->ShowColorChooser(web_contents, initial_color); |
| 104 } |
| 105 |
| 106 void CustomLauncherPageContents::RunFileChooser( |
| 107 content::WebContents* tab, |
| 108 const content::FileChooserParams& params) { |
| 109 app_delegate_->RunFileChooser(tab, params); |
| 110 } |
| 111 |
| 112 void CustomLauncherPageContents::RequestToLockMouse( |
| 113 content::WebContents* web_contents, |
| 114 bool user_gesture, |
| 115 bool last_unlocked_by_target) { |
| 116 DCHECK_EQ(web_contents_.get(), web_contents); |
| 117 helper_->RequestToLockMouse(); |
| 118 } |
| 119 |
| 120 void CustomLauncherPageContents::RequestMediaAccessPermission( |
| 121 content::WebContents* web_contents, |
| 122 const content::MediaStreamRequest& request, |
| 123 const content::MediaResponseCallback& callback) { |
| 124 DCHECK_EQ(web_contents_.get(), web_contents); |
| 125 helper_->RequestMediaAccessPermission(request, callback); |
| 126 } |
| 127 |
52 bool CustomLauncherPageContents::OnMessageReceived( | 128 bool CustomLauncherPageContents::OnMessageReceived( |
53 const IPC::Message& message) { | 129 const IPC::Message& message) { |
54 bool handled = true; | 130 bool handled = true; |
55 IPC_BEGIN_MESSAGE_MAP(CustomLauncherPageContents, message) | 131 IPC_BEGIN_MESSAGE_MAP(CustomLauncherPageContents, message) |
56 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | 132 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
57 IPC_MESSAGE_UNHANDLED(handled = false) | 133 IPC_MESSAGE_UNHANDLED(handled = false) |
58 IPC_END_MESSAGE_MAP() | 134 IPC_END_MESSAGE_MAP() |
59 return handled; | 135 return handled; |
60 } | 136 } |
61 | 137 |
62 extensions::WindowController* | 138 extensions::WindowController* |
63 CustomLauncherPageContents::GetExtensionWindowController() const { | 139 CustomLauncherPageContents::GetExtensionWindowController() const { |
64 return NULL; | 140 return NULL; |
65 } | 141 } |
66 | 142 |
67 content::WebContents* CustomLauncherPageContents::GetAssociatedWebContents() | 143 content::WebContents* CustomLauncherPageContents::GetAssociatedWebContents() |
68 const { | 144 const { |
69 return web_contents(); | 145 return web_contents(); |
70 } | 146 } |
71 | 147 |
72 void CustomLauncherPageContents::OnRequest( | 148 void CustomLauncherPageContents::OnRequest( |
73 const ExtensionHostMsg_Request_Params& params) { | 149 const ExtensionHostMsg_Request_Params& params) { |
74 extension_function_dispatcher_->Dispatch(params, | 150 extension_function_dispatcher_->Dispatch(params, |
75 web_contents_->GetRenderViewHost()); | 151 web_contents_->GetRenderViewHost()); |
76 } | 152 } |
77 | 153 |
78 } // namespace apps | 154 } // namespace apps |
OLD | NEW |