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

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

Issue 13375017: Move the ViewType enum to extensions\common. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 8 months 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/memory/singleton.h" 10 #include "base/memory/singleton.h"
(...skipping 11 matching lines...) Expand all
22 #include "chrome/browser/extensions/window_controller.h" 22 #include "chrome/browser/extensions/window_controller.h"
23 #include "chrome/browser/file_select_helper.h" 23 #include "chrome/browser/file_select_helper.h"
24 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 24 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
25 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.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.h" 27 #include "chrome/browser/ui/browser.h"
28 #include "chrome/browser/ui/browser_finder.h" 28 #include "chrome/browser/ui/browser_finder.h"
29 #include "chrome/browser/ui/browser_list.h" 29 #include "chrome/browser/ui/browser_list.h"
30 #include "chrome/browser/ui/browser_window.h" 30 #include "chrome/browser/ui/browser_window.h"
31 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" 31 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
32 #include "chrome/browser/view_type_utils.h"
33 #include "chrome/common/chrome_constants.h" 32 #include "chrome/common/chrome_constants.h"
34 #include "chrome/common/chrome_notification_types.h" 33 #include "chrome/common/chrome_notification_types.h"
35 #include "chrome/common/extensions/background_info.h" 34 #include "chrome/common/extensions/background_info.h"
36 #include "chrome/common/extensions/extension.h" 35 #include "chrome/common/extensions/extension.h"
37 #include "chrome/common/extensions/extension_constants.h" 36 #include "chrome/common/extensions/extension_constants.h"
38 #include "chrome/common/extensions/extension_messages.h" 37 #include "chrome/common/extensions/extension_messages.h"
39 #include "chrome/common/extensions/feature_switch.h" 38 #include "chrome/common/extensions/feature_switch.h"
40 #include "chrome/common/extensions/request_media_access_permission_helper.h" 39 #include "chrome/common/extensions/request_media_access_permission_helper.h"
41 #include "chrome/common/render_messages.h" 40 #include "chrome/common/render_messages.h"
42 #include "chrome/common/url_constants.h" 41 #include "chrome/common/url_constants.h"
43 #include "content/public/browser/content_browser_client.h" 42 #include "content/public/browser/content_browser_client.h"
44 #include "content/public/browser/native_web_keyboard_event.h" 43 #include "content/public/browser/native_web_keyboard_event.h"
45 #include "content/public/browser/notification_service.h" 44 #include "content/public/browser/notification_service.h"
46 #include "content/public/browser/render_process_host.h" 45 #include "content/public/browser/render_process_host.h"
47 #include "content/public/browser/render_view_host.h" 46 #include "content/public/browser/render_view_host.h"
48 #include "content/public/browser/site_instance.h" 47 #include "content/public/browser/site_instance.h"
49 #include "content/public/browser/web_contents.h" 48 #include "content/public/browser/web_contents.h"
50 #include "content/public/browser/web_contents_view.h" 49 #include "content/public/browser/web_contents_view.h"
50 #include "extensions/browser/view_type_utils.h"
51 #include "grit/browser_resources.h" 51 #include "grit/browser_resources.h"
52 #include "grit/chromium_strings.h" 52 #include "grit/chromium_strings.h"
53 #include "grit/generated_resources.h" 53 #include "grit/generated_resources.h"
54 #include "ui/base/keycodes/keyboard_codes.h" 54 #include "ui/base/keycodes/keyboard_codes.h"
55 #include "ui/base/l10n/l10n_util.h" 55 #include "ui/base/l10n/l10n_util.h"
56 #include "ui/base/resource/resource_bundle.h" 56 #include "ui/base/resource/resource_bundle.h"
57 57
58 using WebKit::WebDragOperation; 58 using WebKit::WebDragOperation;
59 using WebKit::WebDragOperationsMask; 59 using WebKit::WebDragOperationsMask;
60 using content::NativeWebKeyboardEvent; 60 using content::NativeWebKeyboardEvent;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 bool pending_create_; 121 bool pending_create_;
122 base::WeakPtrFactory<ProcessCreationQueue> ptr_factory_; 122 base::WeakPtrFactory<ProcessCreationQueue> ptr_factory_;
123 }; 123 };
124 124
125 //////////////// 125 ////////////////
126 // ExtensionHost 126 // ExtensionHost
127 127
128 ExtensionHost::ExtensionHost(const Extension* extension, 128 ExtensionHost::ExtensionHost(const Extension* extension,
129 SiteInstance* site_instance, 129 SiteInstance* site_instance,
130 const GURL& url, 130 const GURL& url,
131 chrome::ViewType host_type) 131 ViewType host_type)
132 : extension_(extension), 132 : extension_(extension),
133 extension_id_(extension->id()), 133 extension_id_(extension->id()),
134 profile_(Profile::FromBrowserContext( 134 profile_(Profile::FromBrowserContext(
135 site_instance->GetBrowserContext())), 135 site_instance->GetBrowserContext())),
136 render_view_host_(NULL), 136 render_view_host_(NULL),
137 did_stop_loading_(false), 137 did_stop_loading_(false),
138 document_element_available_(false), 138 document_element_available_(false),
139 initial_url_(url), 139 initial_url_(url),
140 ALLOW_THIS_IN_INITIALIZER_LIST( 140 ALLOW_THIS_IN_INITIALIZER_LIST(
141 extension_function_dispatcher_(profile_, this)), 141 extension_function_dispatcher_(profile_, this)),
142 extension_host_type_(host_type), 142 extension_host_type_(host_type),
143 associated_web_contents_(NULL) { 143 associated_web_contents_(NULL) {
144 host_contents_.reset(WebContents::Create( 144 host_contents_.reset(WebContents::Create(
145 WebContents::CreateParams(profile_, site_instance))), 145 WebContents::CreateParams(profile_, site_instance))),
146 content::WebContentsObserver::Observe(host_contents_.get()); 146 content::WebContentsObserver::Observe(host_contents_.get());
147 host_contents_->SetDelegate(this); 147 host_contents_->SetDelegate(this);
148 chrome::SetViewType(host_contents_.get(), host_type); 148 SetViewType(host_contents_.get(), host_type);
149 149
150 PrefsTabHelper::CreateForWebContents(host_contents()); 150 PrefsTabHelper::CreateForWebContents(host_contents());
151 151
152 render_view_host_ = host_contents_->GetRenderViewHost(); 152 render_view_host_ = host_contents_->GetRenderViewHost();
153 153
154 // Listen for when an extension is unloaded from the same profile, as it may 154 // Listen for when an extension is unloaded from the same profile, as it may
155 // be the same extension that this points to. 155 // be the same extension that this points to.
156 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 156 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
157 content::Source<Profile>(profile_)); 157 content::Source<Profile>(profile_));
158 } 158 }
159 159
160 ExtensionHost::~ExtensionHost() { 160 ExtensionHost::~ExtensionHost() {
161 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE && 161 if (extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE &&
162 extension_ && BackgroundInfo::HasLazyBackgroundPage(extension_)) { 162 extension_ && BackgroundInfo::HasLazyBackgroundPage(extension_)) {
163 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime", 163 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime",
164 since_created_.Elapsed()); 164 since_created_.Elapsed());
165 } 165 }
166 // Clear the extension's renderer process out from any WebContents 166 // Clear the extension's renderer process out from any WebContents
167 // that might have it in their back history. 167 // that might have it in their back history.
168 // TODO(jyasskin): Remove this hack by making extension reloading 168 // TODO(jyasskin): Remove this hack by making extension reloading
169 // wait for renderer shutdown. 169 // wait for renderer shutdown.
170 content::NotificationService::current()->Notify( 170 content::NotificationService::current()->Notify(
171 content::NOTIFICATION_RENDERER_PROCESS_CLOSING, 171 content::NOTIFICATION_RENDERER_PROCESS_CLOSING,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 CreateRenderViewNow(); 231 CreateRenderViewNow();
232 } else { 232 } else {
233 ProcessCreationQueue::GetInstance()->CreateSoon(this); 233 ProcessCreationQueue::GetInstance()->CreateSoon(this);
234 } 234 }
235 } 235 }
236 236
237 void ExtensionHost::CreateRenderViewNow() { 237 void ExtensionHost::CreateRenderViewNow() {
238 LoadInitialURL(); 238 LoadInitialURL();
239 if (is_background_page()) { 239 if (is_background_page()) {
240 DCHECK(IsRenderViewLive()); 240 DCHECK(IsRenderViewLive());
241 extensions::ExtensionSystem::Get(profile_)->extension_service()-> 241 ExtensionSystem::Get(profile_)->extension_service()->
242 DidCreateRenderViewForBackgroundPage(this); 242 DidCreateRenderViewForBackgroundPage(this);
243 } 243 }
244 } 244 }
245 245
246 extensions::WindowController* 246 WindowController* ExtensionHost::GetExtensionWindowController() const {
247 ExtensionHost::GetExtensionWindowController() const {
248 return view() && view()->browser() ? 247 return view() && view()->browser() ?
249 view()->browser()->extension_window_controller() : NULL; 248 view()->browser()->extension_window_controller() : NULL;
250 } 249 }
251 250
252 const GURL& ExtensionHost::GetURL() const { 251 const GURL& ExtensionHost::GetURL() const {
253 return host_contents()->GetURL(); 252 return host_contents()->GetURL();
254 } 253 }
255 254
256 void ExtensionHost::LoadInitialURL() { 255 void ExtensionHost::LoadInitialURL() {
257 if (!is_background_page() && 256 if (!is_background_page() &&
258 !extensions::ExtensionSystem::Get(profile_)->extension_service()-> 257 !ExtensionSystem::Get(profile_)->extension_service()->
259 IsBackgroundPageReady(extension_)) { 258 IsBackgroundPageReady(extension_)) {
260 // Make sure the background page loads before any others. 259 // Make sure the background page loads before any others.
261 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, 260 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
262 content::Source<Extension>(extension_)); 261 content::Source<Extension>(extension_));
263 return; 262 return;
264 } 263 }
265 264
266 host_contents_->GetController().LoadURL( 265 host_contents_->GetController().LoadURL(
267 initial_url_, content::Referrer(), content::PAGE_TRANSITION_LINK, 266 initial_url_, content::Referrer(), content::PAGE_TRANSITION_LINK,
268 std::string()); 267 std::string());
269 } 268 }
270 269
271 void ExtensionHost::Close() { 270 void ExtensionHost::Close() {
272 content::NotificationService::current()->Notify( 271 content::NotificationService::current()->Notify(
273 chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, 272 chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
274 content::Source<Profile>(profile_), 273 content::Source<Profile>(profile_),
275 content::Details<ExtensionHost>(this)); 274 content::Details<ExtensionHost>(this));
276 } 275 }
277 276
278 void ExtensionHost::Observe(int type, 277 void ExtensionHost::Observe(int type,
279 const content::NotificationSource& source, 278 const content::NotificationSource& source,
280 const content::NotificationDetails& details) { 279 const content::NotificationDetails& details) {
281 switch (type) { 280 switch (type) {
282 case chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY: 281 case chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY:
283 DCHECK(extensions::ExtensionSystem::Get(profile_)->extension_service()-> 282 DCHECK(ExtensionSystem::Get(profile_)->extension_service()->
284 IsBackgroundPageReady(extension_)); 283 IsBackgroundPageReady(extension_));
285 LoadInitialURL(); 284 LoadInitialURL();
286 break; 285 break;
287 case chrome::NOTIFICATION_EXTENSION_UNLOADED: 286 case chrome::NOTIFICATION_EXTENSION_UNLOADED:
288 // The extension object will be deleted after this notification has been 287 // The extension object will be deleted after this notification has been
289 // sent. NULL it out so that dirty pointer issues don't arise in cases 288 // sent. NULL it out so that dirty pointer issues don't arise in cases
290 // when multiple ExtensionHost objects pointing to the same Extension are 289 // when multiple ExtensionHost objects pointing to the same Extension are
291 // present. 290 // present.
292 if (extension_ == content::Details<UnloadedExtensionInfo>(details)-> 291 if (extension_ == content::Details<UnloadedExtensionInfo>(details)->
293 extension) { 292 extension) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 static const base::StringPiece css( 342 static const base::StringPiece css(
344 ResourceBundle::GetSharedInstance().GetRawDataResource( 343 ResourceBundle::GetSharedInstance().GetRawDataResource(
345 IDR_EXTENSIONS_INFOBAR_CSS)); 344 IDR_EXTENSIONS_INFOBAR_CSS));
346 345
347 render_view_host()->InsertCSS(string16(), css.as_string()); 346 render_view_host()->InsertCSS(string16(), css.as_string());
348 } 347 }
349 348
350 void ExtensionHost::DidStopLoading(content::RenderViewHost* render_view_host) { 349 void ExtensionHost::DidStopLoading(content::RenderViewHost* render_view_host) {
351 bool notify = !did_stop_loading_; 350 bool notify = !did_stop_loading_;
352 did_stop_loading_ = true; 351 did_stop_loading_ = true;
353 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP || 352 if (extension_host_type_ == VIEW_TYPE_EXTENSION_POPUP ||
354 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG || 353 extension_host_type_ == VIEW_TYPE_EXTENSION_DIALOG ||
355 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR || 354 extension_host_type_ == VIEW_TYPE_EXTENSION_INFOBAR ||
356 extension_host_type_ == chrome::VIEW_TYPE_PANEL) { 355 extension_host_type_ == VIEW_TYPE_PANEL) {
357 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) 356 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX)
358 if (view()) 357 if (view())
359 view()->DidStopLoading(); 358 view()->DidStopLoading();
360 #endif 359 #endif
361 } 360 }
362 if (notify) { 361 if (notify) {
363 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { 362 if (extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
364 if (extension_ && BackgroundInfo::HasLazyBackgroundPage(extension_)) { 363 if (extension_ && BackgroundInfo::HasLazyBackgroundPage(extension_)) {
365 UMA_HISTOGRAM_TIMES("Extensions.EventPageLoadTime", 364 UMA_HISTOGRAM_TIMES("Extensions.EventPageLoadTime",
366 since_created_.Elapsed()); 365 since_created_.Elapsed());
367 } else { 366 } else {
368 UMA_HISTOGRAM_TIMES("Extensions.BackgroundPageLoadTime", 367 UMA_HISTOGRAM_TIMES("Extensions.BackgroundPageLoadTime",
369 since_created_.Elapsed()); 368 since_created_.Elapsed());
370 } 369 }
371 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG) { 370 } else if (extension_host_type_ == VIEW_TYPE_EXTENSION_DIALOG) {
372 UMA_HISTOGRAM_TIMES("Extensions.DialogLoadTime", 371 UMA_HISTOGRAM_TIMES("Extensions.DialogLoadTime",
373 since_created_.Elapsed()); 372 since_created_.Elapsed());
374 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP) { 373 } else if (extension_host_type_ == VIEW_TYPE_EXTENSION_POPUP) {
375 UMA_HISTOGRAM_TIMES("Extensions.PopupLoadTime", 374 UMA_HISTOGRAM_TIMES("Extensions.PopupLoadTime",
376 since_created_.Elapsed()); 375 since_created_.Elapsed());
377 } else if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR) { 376 } else if (extension_host_type_ == VIEW_TYPE_EXTENSION_INFOBAR) {
378 UMA_HISTOGRAM_TIMES("Extensions.InfobarLoadTime", 377 UMA_HISTOGRAM_TIMES("Extensions.InfobarLoadTime",
379 since_created_.Elapsed()); 378 since_created_.Elapsed());
380 } else if (extension_host_type_ == chrome::VIEW_TYPE_PANEL) { 379 } else if (extension_host_type_ == VIEW_TYPE_PANEL) {
381 UMA_HISTOGRAM_TIMES("Extensions.PanelLoadTime", since_created_.Elapsed()); 380 UMA_HISTOGRAM_TIMES("Extensions.PanelLoadTime", since_created_.Elapsed());
382 } 381 }
383 382
384 // Send the notification last, because it might result in this being 383 // Send the notification last, because it might result in this being
385 // deleted. 384 // deleted.
386 content::NotificationService::current()->Notify( 385 content::NotificationService::current()->Notify(
387 chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, 386 chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
388 content::Source<Profile>(profile_), 387 content::Source<Profile>(profile_),
389 content::Details<ExtensionHost>(this)); 388 content::Details<ExtensionHost>(this));
390 } 389 }
391 } 390 }
392 391
393 void ExtensionHost::DocumentAvailableInMainFrame() { 392 void ExtensionHost::DocumentAvailableInMainFrame() {
394 // If the document has already been marked as available for this host, then 393 // If the document has already been marked as available for this host, then
395 // bail. No need for the redundant setup. http://crbug.com/31170 394 // bail. No need for the redundant setup. http://crbug.com/31170
396 if (document_element_available_) 395 if (document_element_available_)
397 return; 396 return;
398 397
399 document_element_available_ = true; 398 document_element_available_ = true;
400 if (is_background_page()) { 399 if (is_background_page()) {
401 extensions::ExtensionSystem::Get(profile_)->extension_service()-> 400 ExtensionSystem::Get(profile_)->extension_service()->
402 SetBackgroundPageReady(extension_); 401 SetBackgroundPageReady(extension_);
403 } else { 402 } else {
404 switch (extension_host_type_) { 403 switch (extension_host_type_) {
405 case chrome::VIEW_TYPE_EXTENSION_INFOBAR: 404 case VIEW_TYPE_EXTENSION_INFOBAR:
406 InsertInfobarCSS(); 405 InsertInfobarCSS();
407 break; 406 break;
408 default: 407 default:
409 break; // No style sheet for other types, at the moment. 408 break; // No style sheet for other types, at the moment.
410 } 409 }
411 } 410 }
412 } 411 }
413 412
414 void ExtensionHost::CloseContents(WebContents* contents) { 413 void ExtensionHost::CloseContents(WebContents* contents) {
415 // TODO(mpcomplete): is this check really necessary? 414 // TODO(mpcomplete): is this check really necessary?
416 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP || 415 if (extension_host_type_ == VIEW_TYPE_EXTENSION_POPUP ||
417 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_DIALOG || 416 extension_host_type_ == VIEW_TYPE_EXTENSION_DIALOG ||
418 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE || 417 extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE ||
419 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR || 418 extension_host_type_ == VIEW_TYPE_EXTENSION_INFOBAR ||
420 extension_host_type_ == chrome::VIEW_TYPE_PANEL) { 419 extension_host_type_ == VIEW_TYPE_PANEL) {
421 Close(); 420 Close();
422 } 421 }
423 } 422 }
424 423
425 void ExtensionHost::WillRunJavaScriptDialog() { 424 void ExtensionHost::WillRunJavaScriptDialog() {
426 ExtensionProcessManager* pm = 425 ExtensionProcessManager* pm =
427 ExtensionSystem::Get(profile_)->process_manager(); 426 ExtensionSystem::Get(profile_)->process_manager();
428 if (pm) 427 if (pm)
429 pm->IncrementLazyKeepaliveCount(extension()); 428 pm->IncrementLazyKeepaliveCount(extension());
430 } 429 }
(...skipping 22 matching lines...) Expand all
453 return browser ? browser->OpenURL(params) : NULL; 452 return browser ? browser->OpenURL(params) : NULL;
454 } 453 }
455 default: 454 default:
456 return NULL; 455 return NULL;
457 } 456 }
458 } 457 }
459 458
460 bool ExtensionHost::PreHandleKeyboardEvent(WebContents* source, 459 bool ExtensionHost::PreHandleKeyboardEvent(WebContents* source,
461 const NativeWebKeyboardEvent& event, 460 const NativeWebKeyboardEvent& event,
462 bool* is_keyboard_shortcut) { 461 bool* is_keyboard_shortcut) {
463 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP && 462 if (extension_host_type_ == VIEW_TYPE_EXTENSION_POPUP &&
464 event.type == NativeWebKeyboardEvent::RawKeyDown && 463 event.type == NativeWebKeyboardEvent::RawKeyDown &&
465 event.windowsKeyCode == ui::VKEY_ESCAPE) { 464 event.windowsKeyCode == ui::VKEY_ESCAPE) {
466 DCHECK(is_keyboard_shortcut != NULL); 465 DCHECK(is_keyboard_shortcut != NULL);
467 *is_keyboard_shortcut = true; 466 *is_keyboard_shortcut = true;
468 return false; 467 return false;
469 } 468 }
470 469
471 // Handle higher priority browser shortcuts such as Ctrl-w. 470 // Handle higher priority browser shortcuts such as Ctrl-w.
472 Browser* browser = view() ? view()->browser() : NULL; 471 Browser* browser = view() ? view()->browser() : NULL;
473 if (browser) 472 if (browser)
474 return browser->PreHandleKeyboardEvent(source, event, is_keyboard_shortcut); 473 return browser->PreHandleKeyboardEvent(source, event, is_keyboard_shortcut);
475 474
476 *is_keyboard_shortcut = false; 475 *is_keyboard_shortcut = false;
477 return false; 476 return false;
478 } 477 }
479 478
480 void ExtensionHost::HandleKeyboardEvent(WebContents* source, 479 void ExtensionHost::HandleKeyboardEvent(WebContents* source,
481 const NativeWebKeyboardEvent& event) { 480 const NativeWebKeyboardEvent& event) {
482 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP) { 481 if (extension_host_type_ == VIEW_TYPE_EXTENSION_POPUP) {
483 if (event.type == NativeWebKeyboardEvent::RawKeyDown && 482 if (event.type == NativeWebKeyboardEvent::RawKeyDown &&
484 event.windowsKeyCode == ui::VKEY_ESCAPE) { 483 event.windowsKeyCode == ui::VKEY_ESCAPE) {
485 Close(); 484 Close();
486 return; 485 return;
487 } 486 }
488 } 487 }
489 UnhandledKeyboardEvent(source, event); 488 UnhandledKeyboardEvent(source, event);
490 } 489 }
491 490
492 bool ExtensionHost::OnMessageReceived(const IPC::Message& message) { 491 bool ExtensionHost::OnMessageReceived(const IPC::Message& message) {
493 bool handled = true; 492 bool handled = true;
494 IPC_BEGIN_MESSAGE_MAP(ExtensionHost, message) 493 IPC_BEGIN_MESSAGE_MAP(ExtensionHost, message)
495 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) 494 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
496 IPC_MESSAGE_HANDLER(ExtensionHostMsg_EventAck, OnEventAck) 495 IPC_MESSAGE_HANDLER(ExtensionHostMsg_EventAck, OnEventAck)
497 IPC_MESSAGE_HANDLER(ExtensionHostMsg_IncrementLazyKeepaliveCount, 496 IPC_MESSAGE_HANDLER(ExtensionHostMsg_IncrementLazyKeepaliveCount,
498 OnIncrementLazyKeepaliveCount) 497 OnIncrementLazyKeepaliveCount)
499 IPC_MESSAGE_HANDLER(ExtensionHostMsg_DecrementLazyKeepaliveCount, 498 IPC_MESSAGE_HANDLER(ExtensionHostMsg_DecrementLazyKeepaliveCount,
500 OnDecrementLazyKeepaliveCount) 499 OnDecrementLazyKeepaliveCount)
501 IPC_MESSAGE_UNHANDLED(handled = false) 500 IPC_MESSAGE_UNHANDLED(handled = false)
502 IPC_END_MESSAGE_MAP() 501 IPC_END_MESSAGE_MAP()
503 return handled; 502 return handled;
504 } 503 }
505 504
506 void ExtensionHost::OnRequest(const ExtensionHostMsg_Request_Params& params) { 505 void ExtensionHost::OnRequest(const ExtensionHostMsg_Request_Params& params) {
507 extension_function_dispatcher_.Dispatch(params, render_view_host()); 506 extension_function_dispatcher_.Dispatch(params, render_view_host());
508 } 507 }
509 508
510 void ExtensionHost::OnEventAck() { 509 void ExtensionHost::OnEventAck() {
511 extensions::EventRouter* router = 510 EventRouter* router = ExtensionSystem::Get(profile_)->event_router();
512 ExtensionSystem::Get(profile_)->event_router();
513 if (router) 511 if (router)
514 router->OnEventAck(profile_, extension_id()); 512 router->OnEventAck(profile_, extension_id());
515 } 513 }
516 514
517 void ExtensionHost::OnIncrementLazyKeepaliveCount() { 515 void ExtensionHost::OnIncrementLazyKeepaliveCount() {
518 ExtensionProcessManager* pm = 516 ExtensionProcessManager* pm =
519 ExtensionSystem::Get(profile_)->process_manager(); 517 ExtensionSystem::Get(profile_)->process_manager();
520 if (pm) 518 if (pm)
521 pm->IncrementLazyKeepaliveCount(extension()); 519 pm->IncrementLazyKeepaliveCount(extension());
522 } 520 }
(...skipping 25 matching lines...) Expand all
548 } 546 }
549 547
550 void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) { 548 void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) {
551 render_view_host_ = render_view_host; 549 render_view_host_ = render_view_host;
552 550
553 if (view()) 551 if (view())
554 view()->RenderViewCreated(); 552 view()->RenderViewCreated();
555 553
556 // If the host is bound to a window, then extract its id. Extensions hosted 554 // If the host is bound to a window, then extract its id. Extensions hosted
557 // in ExternalTabContainer objects may not have an associated window. 555 // in ExternalTabContainer objects may not have an associated window.
558 extensions::WindowController* window = GetExtensionWindowController(); 556 WindowController* window = GetExtensionWindowController();
559 if (window) { 557 if (window) {
560 render_view_host->Send(new ExtensionMsg_UpdateBrowserWindowId( 558 render_view_host->Send(new ExtensionMsg_UpdateBrowserWindowId(
561 render_view_host->GetRoutingID(), window->GetWindowId())); 559 render_view_host->GetRoutingID(), window->GetWindowId()));
562 } 560 }
563 } 561 }
564 562
565 void ExtensionHost::RenderViewDeleted(RenderViewHost* render_view_host) { 563 void ExtensionHost::RenderViewDeleted(RenderViewHost* render_view_host) {
566 // If our RenderViewHost is deleted, fall back to the host_contents' current 564 // If our RenderViewHost is deleted, fall back to the host_contents' current
567 // RVH. There is sometimes a small gap between the pending RVH being deleted 565 // RVH. There is sometimes a small gap between the pending RVH being deleted
568 // and RenderViewCreated being called, so we update it here. 566 // and RenderViewCreated being called, so we update it here.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 content::IsAudioMediaType(request.audio_type), 631 content::IsAudioMediaType(request.audio_type),
634 content::IsVideoMediaType(request.video_type), 632 content::IsVideoMediaType(request.video_type),
635 &devices); 633 &devices);
636 634
637 // For tab capture device, we require the tabCapture permission. 635 // For tab capture device, we require the tabCapture permission.
638 RequestMediaAccessPermissionHelper::AuthorizeRequest( 636 RequestMediaAccessPermissionHelper::AuthorizeRequest(
639 devices, request, callback, extension(), false); 637 devices, request, callback, extension(), false);
640 } 638 }
641 639
642 } // namespace extensions 640 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698