OLD | NEW |
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/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
18 #include "chrome/browser/extensions/error_console/error_console.h" | 18 #include "chrome/browser/extensions/error_console/error_console.h" |
19 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
20 #include "chrome/browser/extensions/extension_system.h" | |
21 #include "chrome/browser/extensions/extension_tab_util.h" | 20 #include "chrome/browser/extensions/extension_tab_util.h" |
22 #include "chrome/browser/extensions/extension_web_contents_observer.h" | 21 #include "chrome/browser/extensions/extension_web_contents_observer.h" |
23 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 22 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
24 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
25 #include "chrome/common/extensions/extension_constants.h" | 24 #include "chrome/common/extensions/extension_constants.h" |
26 #include "chrome/common/extensions/extension_messages.h" | 25 #include "chrome/common/extensions/extension_messages.h" |
27 #include "chrome/common/render_messages.h" | 26 #include "chrome/common/render_messages.h" |
28 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
29 #include "content/public/browser/browser_context.h" | 28 #include "content/public/browser/browser_context.h" |
30 #include "content/public/browser/content_browser_client.h" | 29 #include "content/public/browser/content_browser_client.h" |
31 #include "content/public/browser/native_web_keyboard_event.h" | 30 #include "content/public/browser/native_web_keyboard_event.h" |
32 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
33 #include "content/public/browser/notification_source.h" | 32 #include "content/public/browser/notification_source.h" |
34 #include "content/public/browser/notification_types.h" | 33 #include "content/public/browser/notification_types.h" |
35 #include "content/public/browser/render_process_host.h" | 34 #include "content/public/browser/render_process_host.h" |
36 #include "content/public/browser/render_view_host.h" | 35 #include "content/public/browser/render_view_host.h" |
37 #include "content/public/browser/render_widget_host_view.h" | 36 #include "content/public/browser/render_widget_host_view.h" |
38 #include "content/public/browser/site_instance.h" | 37 #include "content/public/browser/site_instance.h" |
39 #include "content/public/browser/web_contents.h" | 38 #include "content/public/browser/web_contents.h" |
40 #include "extensions/browser/event_router.h" | 39 #include "extensions/browser/event_router.h" |
41 #include "extensions/browser/extension_error.h" | 40 #include "extensions/browser/extension_error.h" |
| 41 #include "extensions/browser/extension_system.h" |
42 #include "extensions/browser/extensions_browser_client.h" | 42 #include "extensions/browser/extensions_browser_client.h" |
43 #include "extensions/browser/process_manager.h" | 43 #include "extensions/browser/process_manager.h" |
44 #include "extensions/browser/runtime_data.h" | 44 #include "extensions/browser/runtime_data.h" |
45 #include "extensions/browser/view_type_utils.h" | 45 #include "extensions/browser/view_type_utils.h" |
46 #include "extensions/common/extension.h" | 46 #include "extensions/common/extension.h" |
47 #include "extensions/common/extension_urls.h" | 47 #include "extensions/common/extension_urls.h" |
48 #include "extensions/common/feature_switch.h" | 48 #include "extensions/common/feature_switch.h" |
49 #include "extensions/common/manifest_handlers/background_info.h" | 49 #include "extensions/common/manifest_handlers/background_info.h" |
50 #include "ui/base/l10n/l10n_util.h" | 50 #include "ui/base/l10n/l10n_util.h" |
51 #include "ui/base/window_open_disposition.h" | 51 #include "ui/base/window_open_disposition.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 LoadInitialURL(); | 196 LoadInitialURL(); |
197 if (!IsBackgroundPage()) { | 197 if (!IsBackgroundPage()) { |
198 DCHECK(IsRenderViewLive()); | 198 DCHECK(IsRenderViewLive()); |
199 ExtensionService* service = GetExtensionService(); | 199 ExtensionService* service = GetExtensionService(); |
200 if (service) | 200 if (service) |
201 service->DidCreateRenderViewForBackgroundPage(this); | 201 service->DidCreateRenderViewForBackgroundPage(this); |
202 } | 202 } |
203 } | 203 } |
204 | 204 |
205 ExtensionService* ExtensionHost::GetExtensionService() { | 205 ExtensionService* ExtensionHost::GetExtensionService() { |
206 return ExtensionSystem::GetForBrowserContext(browser_context_) | 206 return ExtensionSystem::Get(browser_context_) |
207 ->extension_service(); | 207 ->extension_service(); |
208 } | 208 } |
209 | 209 |
210 const GURL& ExtensionHost::GetURL() const { | 210 const GURL& ExtensionHost::GetURL() const { |
211 return host_contents()->GetURL(); | 211 return host_contents()->GetURL(); |
212 } | 212 } |
213 | 213 |
214 void ExtensionHost::LoadInitialURL() { | 214 void ExtensionHost::LoadInitialURL() { |
215 host_contents_->GetController().LoadURL( | 215 host_contents_->GetController().LoadURL( |
216 initial_url_, content::Referrer(), content::PAGE_TRANSITION_LINK, | 216 initial_url_, content::Referrer(), content::PAGE_TRANSITION_LINK, |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 // If the document has already been marked as available for this host, then | 317 // If the document has already been marked as available for this host, then |
318 // bail. No need for the redundant setup. http://crbug.com/31170 | 318 // bail. No need for the redundant setup. http://crbug.com/31170 |
319 if (document_element_available_) | 319 if (document_element_available_) |
320 return; | 320 return; |
321 document_element_available_ = true; | 321 document_element_available_ = true; |
322 OnDocumentAvailable(); | 322 OnDocumentAvailable(); |
323 } | 323 } |
324 | 324 |
325 void ExtensionHost::OnDocumentAvailable() { | 325 void ExtensionHost::OnDocumentAvailable() { |
326 DCHECK(extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); | 326 DCHECK(extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); |
327 ExtensionSystem::GetForBrowserContext(browser_context_) | 327 ExtensionSystem::Get(browser_context_) |
328 ->runtime_data() | 328 ->runtime_data() |
329 ->SetBackgroundPageReady(extension_, true); | 329 ->SetBackgroundPageReady(extension_, true); |
330 content::NotificationService::current()->Notify( | 330 content::NotificationService::current()->Notify( |
331 chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, | 331 chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, |
332 content::Source<const Extension>(extension_), | 332 content::Source<const Extension>(extension_), |
333 content::NotificationService::NoDetails()); | 333 content::NotificationService::NoDetails()); |
334 } | 334 } |
335 | 335 |
336 void ExtensionHost::CloseContents(WebContents* contents) { | 336 void ExtensionHost::CloseContents(WebContents* contents) { |
337 Close(); | 337 Close(); |
(...skipping 14 matching lines...) Expand all Loading... |
352 IPC_END_MESSAGE_MAP() | 352 IPC_END_MESSAGE_MAP() |
353 return handled; | 353 return handled; |
354 } | 354 } |
355 | 355 |
356 void ExtensionHost::OnRequest(const ExtensionHostMsg_Request_Params& params) { | 356 void ExtensionHost::OnRequest(const ExtensionHostMsg_Request_Params& params) { |
357 extension_function_dispatcher_.Dispatch(params, render_view_host()); | 357 extension_function_dispatcher_.Dispatch(params, render_view_host()); |
358 } | 358 } |
359 | 359 |
360 void ExtensionHost::OnEventAck() { | 360 void ExtensionHost::OnEventAck() { |
361 EventRouter* router = | 361 EventRouter* router = |
362 ExtensionSystem::GetForBrowserContext(browser_context_)->event_router(); | 362 ExtensionSystem::Get(browser_context_)->event_router(); |
363 if (router) | 363 if (router) |
364 router->OnEventAck(browser_context_, extension_id()); | 364 router->OnEventAck(browser_context_, extension_id()); |
365 } | 365 } |
366 | 366 |
367 void ExtensionHost::OnIncrementLazyKeepaliveCount() { | 367 void ExtensionHost::OnIncrementLazyKeepaliveCount() { |
368 ProcessManager* pm = ExtensionSystem::GetForBrowserContext( | 368 ProcessManager* pm = ExtensionSystem::Get( |
369 browser_context_)->process_manager(); | 369 browser_context_)->process_manager(); |
370 if (pm) | 370 if (pm) |
371 pm->IncrementLazyKeepaliveCount(extension()); | 371 pm->IncrementLazyKeepaliveCount(extension()); |
372 } | 372 } |
373 | 373 |
374 void ExtensionHost::OnDecrementLazyKeepaliveCount() { | 374 void ExtensionHost::OnDecrementLazyKeepaliveCount() { |
375 ProcessManager* pm = ExtensionSystem::GetForBrowserContext( | 375 ProcessManager* pm = ExtensionSystem::Get( |
376 browser_context_)->process_manager(); | 376 browser_context_)->process_manager(); |
377 if (pm) | 377 if (pm) |
378 pm->DecrementLazyKeepaliveCount(extension()); | 378 pm->DecrementLazyKeepaliveCount(extension()); |
379 } | 379 } |
380 | 380 |
381 void ExtensionHost::OnDetailedConsoleMessageAdded( | 381 void ExtensionHost::OnDetailedConsoleMessageAdded( |
382 const base::string16& message, | 382 const base::string16& message, |
383 const base::string16& source, | 383 const base::string16& source, |
384 const StackTrace& stack_trace, | 384 const StackTrace& stack_trace, |
385 int32 severity_level) { | 385 int32 severity_level) { |
386 if (!IsSourceFromAnExtension(source)) | 386 if (!IsSourceFromAnExtension(source)) |
387 return; | 387 return; |
388 | 388 |
389 GURL context_url; | 389 GURL context_url; |
390 WebContents* associated_contents = GetAssociatedWebContents(); | 390 WebContents* associated_contents = GetAssociatedWebContents(); |
391 if (associated_contents) | 391 if (associated_contents) |
392 context_url = associated_contents->GetLastCommittedURL(); | 392 context_url = associated_contents->GetLastCommittedURL(); |
393 else if (host_contents_.get()) | 393 else if (host_contents_.get()) |
394 context_url = host_contents_->GetLastCommittedURL(); | 394 context_url = host_contents_->GetLastCommittedURL(); |
395 | 395 |
396 ErrorConsole* console = | 396 ErrorConsole* console = |
397 ExtensionSystem::GetForBrowserContext(browser_context_)->error_console(); | 397 ExtensionSystem::Get(browser_context_)->error_console(); |
398 if (!console) | 398 if (!console) |
399 return; | 399 return; |
400 | 400 |
401 console->ReportError( | 401 console->ReportError( |
402 scoped_ptr<ExtensionError>(new RuntimeError( | 402 scoped_ptr<ExtensionError>(new RuntimeError( |
403 extension_id_, | 403 extension_id_, |
404 browser_context_->IsOffTheRecord(), | 404 browser_context_->IsOffTheRecord(), |
405 source, | 405 source, |
406 message, | 406 message, |
407 stack_trace, | 407 stack_trace, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 | 471 |
472 void ExtensionHost::RequestMediaAccessPermission( | 472 void ExtensionHost::RequestMediaAccessPermission( |
473 content::WebContents* web_contents, | 473 content::WebContents* web_contents, |
474 const content::MediaStreamRequest& request, | 474 const content::MediaStreamRequest& request, |
475 const content::MediaResponseCallback& callback) { | 475 const content::MediaResponseCallback& callback) { |
476 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( | 476 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( |
477 web_contents, request, callback, extension()); | 477 web_contents, request, callback, extension()); |
478 } | 478 } |
479 | 479 |
480 } // namespace extensions | 480 } // namespace extensions |
OLD | NEW |