Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: chrome/browser/extensions/extension_host.cc

Issue 92743002: Extract UI dependencies from ExtensionHost, part 3 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase extension_view_host Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/extensions/extension_host.h" 5 #include "chrome/browser/extensions/extension_host.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/singleton.h" 11 #include "base/memory/singleton.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "chrome/browser/browser_shutdown.h" 17 #include "chrome/browser/browser_shutdown.h"
18 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/extensions/error_console/error_console.h" 19 #include "chrome/browser/extensions/error_console/error_console.h"
20 #include "chrome/browser/extensions/extension_service.h" 20 #include "chrome/browser/extensions/extension_service.h"
21 #include "chrome/browser/extensions/extension_system.h" 21 #include "chrome/browser/extensions/extension_system.h"
22 #include "chrome/browser/extensions/extension_tab_util.h" 22 #include "chrome/browser/extensions/extension_tab_util.h"
23 #include "chrome/browser/extensions/extension_web_contents_observer.h" 23 #include "chrome/browser/extensions/extension_web_contents_observer.h"
24 #include "chrome/browser/file_select_helper.h" 24 #include "chrome/browser/file_select_helper.h"
25 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 25 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
26 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.h" 26 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.h"
27 #include "chrome/browser/ui/browser_dialogs.h" 27 #include "chrome/browser/ui/browser_dialogs.h"
28 #include "chrome/browser/ui/browser_window.h"
29 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" 28 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
30 #include "chrome/common/chrome_constants.h" 29 #include "chrome/common/chrome_constants.h"
31 #include "chrome/common/extensions/extension_constants.h" 30 #include "chrome/common/extensions/extension_constants.h"
32 #include "chrome/common/extensions/extension_messages.h" 31 #include "chrome/common/extensions/extension_messages.h"
33 #include "chrome/common/render_messages.h" 32 #include "chrome/common/render_messages.h"
34 #include "chrome/common/url_constants.h" 33 #include "chrome/common/url_constants.h"
34 #include "content/public/browser/browser_context.h"
35 #include "content/public/browser/content_browser_client.h" 35 #include "content/public/browser/content_browser_client.h"
36 #include "content/public/browser/native_web_keyboard_event.h" 36 #include "content/public/browser/native_web_keyboard_event.h"
37 #include "content/public/browser/notification_service.h" 37 #include "content/public/browser/notification_service.h"
38 #include "content/public/browser/render_process_host.h" 38 #include "content/public/browser/render_process_host.h"
39 #include "content/public/browser/render_view_host.h" 39 #include "content/public/browser/render_view_host.h"
40 #include "content/public/browser/render_widget_host_view.h" 40 #include "content/public/browser/render_widget_host_view.h"
41 #include "content/public/browser/site_instance.h" 41 #include "content/public/browser/site_instance.h"
42 #include "content/public/browser/web_contents.h" 42 #include "content/public/browser/web_contents.h"
43 #include "content/public/browser/web_contents_view.h"
44 #include "extensions/browser/event_router.h" 43 #include "extensions/browser/event_router.h"
45 #include "extensions/browser/extension_error.h" 44 #include "extensions/browser/extension_error.h"
46 #include "extensions/browser/process_manager.h" 45 #include "extensions/browser/process_manager.h"
47 #include "extensions/browser/view_type_utils.h" 46 #include "extensions/browser/view_type_utils.h"
48 #include "extensions/common/extension.h" 47 #include "extensions/common/extension.h"
49 #include "extensions/common/extension_urls.h" 48 #include "extensions/common/extension_urls.h"
50 #include "extensions/common/feature_switch.h" 49 #include "extensions/common/feature_switch.h"
51 #include "extensions/common/manifest_handlers/background_info.h" 50 #include "extensions/common/manifest_handlers/background_info.h"
52 #include "ui/base/l10n/l10n_util.h" 51 #include "ui/base/l10n/l10n_util.h"
53 52 #include "ui/base/window_open_disposition.h"
54 #if !defined(OS_ANDROID)
55 #include "components/web_modal/web_contents_modal_dialog_manager.h"
56 #endif
57 53
58 using blink::WebDragOperation; 54 using blink::WebDragOperation;
59 using blink::WebDragOperationsMask; 55 using blink::WebDragOperationsMask;
60 using content::BrowserContext; 56 using content::BrowserContext;
61 using content::NativeWebKeyboardEvent; 57 using content::NativeWebKeyboardEvent;
62 using content::OpenURLParams; 58 using content::OpenURLParams;
63 using content::RenderViewHost; 59 using content::RenderViewHost;
64 using content::SiteInstance; 60 using content::SiteInstance;
65 using content::WebContents; 61 using content::WebContents;
66 62
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 ExtensionSystem::GetForBrowserContext(browser_context_)-> 201 ExtensionSystem::GetForBrowserContext(browser_context_)->
206 extension_service()->DidCreateRenderViewForBackgroundPage(this); 202 extension_service()->DidCreateRenderViewForBackgroundPage(this);
207 } 203 }
208 } 204 }
209 205
210 const GURL& ExtensionHost::GetURL() const { 206 const GURL& ExtensionHost::GetURL() const {
211 return host_contents()->GetURL(); 207 return host_contents()->GetURL();
212 } 208 }
213 209
214 void ExtensionHost::LoadInitialURL() { 210 void ExtensionHost::LoadInitialURL() {
215 if (!IsBackgroundPage() &&
216 !ExtensionSystem::GetForBrowserContext(browser_context_)->
217 extension_service()->IsBackgroundPageReady(extension_)) {
218 // Make sure the background page loads before any others.
219 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
220 content::Source<Extension>(extension_));
221 return;
222 }
223
224 #if !defined(OS_ANDROID)
225 // TODO(jamescook): Move this to ExtensionViewHost, which handles popups.
226 if (extension_host_type_ == VIEW_TYPE_EXTENSION_POPUP) {
227 web_modal::WebContentsModalDialogManager::CreateForWebContents(
228 host_contents_.get());
229 web_modal::WebContentsModalDialogManager::FromWebContents(
230 host_contents_.get())->SetDelegate(this);
231 }
232 #endif
233
234 host_contents_->GetController().LoadURL( 211 host_contents_->GetController().LoadURL(
235 initial_url_, content::Referrer(), content::PAGE_TRANSITION_LINK, 212 initial_url_, content::Referrer(), content::PAGE_TRANSITION_LINK,
236 std::string()); 213 std::string());
237 } 214 }
238 215
239 bool ExtensionHost::IsBackgroundPage() const { 216 bool ExtensionHost::IsBackgroundPage() const {
240 DCHECK(extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); 217 DCHECK(extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
241 return true; 218 return true;
242 } 219 }
243 220
244 void ExtensionHost::Close() { 221 void ExtensionHost::Close() {
245 content::NotificationService::current()->Notify( 222 content::NotificationService::current()->Notify(
246 chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, 223 chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
247 content::Source<BrowserContext>(browser_context_), 224 content::Source<BrowserContext>(browser_context_),
248 content::Details<ExtensionHost>(this)); 225 content::Details<ExtensionHost>(this));
249 } 226 }
250 227
251 #if !defined(OS_ANDROID)
252 web_modal::WebContentsModalDialogHost*
253 ExtensionHost::GetWebContentsModalDialogHost() {
254 return this;
255 }
256
257 gfx::NativeView ExtensionHost::GetHostView() const {
258 return NULL;
259 }
260
261 gfx::Point ExtensionHost::GetDialogPosition(const gfx::Size& size) {
262 if (!GetVisibleWebContents())
263 return gfx::Point();
264 gfx::Rect bounds = GetVisibleWebContents()->GetView()->GetViewBounds();
265 return gfx::Point(
266 std::max(0, (bounds.width() - size.width()) / 2),
267 std::max(0, (bounds.height() - size.height()) / 2));
268 }
269
270 gfx::Size ExtensionHost::GetMaximumDialogSize() {
271 if (!GetVisibleWebContents())
272 return gfx::Size();
273 return GetVisibleWebContents()->GetView()->GetViewBounds().size();
274 }
275
276 void ExtensionHost::AddObserver(
277 web_modal::ModalDialogHostObserver* observer) {
278 }
279
280 void ExtensionHost::RemoveObserver(
281 web_modal::ModalDialogHostObserver* observer) {
282 }
283 #endif
284
285 void ExtensionHost::Observe(int type, 228 void ExtensionHost::Observe(int type,
286 const content::NotificationSource& source, 229 const content::NotificationSource& source,
287 const content::NotificationDetails& details) { 230 const content::NotificationDetails& details) {
288 switch (type) { 231 switch (type) {
289 case chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY:
290 DCHECK(ExtensionSystem::GetForBrowserContext(browser_context_)->
291 extension_service()->IsBackgroundPageReady(extension_));
292 LoadInitialURL();
293 break;
294 case chrome::NOTIFICATION_EXTENSION_UNLOADED: 232 case chrome::NOTIFICATION_EXTENSION_UNLOADED:
295 // The extension object will be deleted after this notification has been 233 // The extension object will be deleted after this notification has been
296 // sent. NULL it out so that dirty pointer issues don't arise in cases 234 // sent. NULL it out so that dirty pointer issues don't arise in cases
297 // when multiple ExtensionHost objects pointing to the same Extension are 235 // when multiple ExtensionHost objects pointing to the same Extension are
298 // present. 236 // present.
299 if (extension_ == content::Details<UnloadedExtensionInfo>(details)-> 237 if (extension_ == content::Details<UnloadedExtensionInfo>(details)->
300 extension) { 238 extension) {
301 extension_ = NULL; 239 extension_ = NULL;
302 } 240 }
303 break; 241 break;
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 490
553 void ExtensionHost::RequestMediaAccessPermission( 491 void ExtensionHost::RequestMediaAccessPermission(
554 content::WebContents* web_contents, 492 content::WebContents* web_contents,
555 const content::MediaStreamRequest& request, 493 const content::MediaStreamRequest& request,
556 const content::MediaResponseCallback& callback) { 494 const content::MediaResponseCallback& callback) {
557 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( 495 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest(
558 web_contents, request, callback, extension()); 496 web_contents, request, callback, extension());
559 } 497 }
560 498
561 } // namespace extensions 499 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_host.h ('k') | chrome/browser/extensions/extension_view_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698