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

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

Issue 402673003: Move ExtensionHostMsg_PostMessage IPC handling from (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use override thread Created 6 years, 5 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 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 "chrome/browser/extensions/chrome_extension_web_contents_observer.h" 5 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
6 6
7 #include "chrome/browser/extensions/api/messaging/message_service.h"
8 #include "chrome/browser/extensions/error_console/error_console.h" 7 #include "chrome/browser/extensions/error_console/error_console.h"
9 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/common/extensions/chrome_extension_messages.h" 9 #include "chrome/common/extensions/chrome_extension_messages.h"
11 #include "content/public/browser/browser_context.h" 10 #include "content/public/browser/browser_context.h"
12 #include "content/public/browser/render_process_host.h" 11 #include "content/public/browser/render_process_host.h"
13 #include "content/public/browser/render_view_host.h" 12 #include "content/public/browser/render_view_host.h"
14 #include "extensions/browser/extension_registry.h" 13 #include "extensions/browser/extension_registry.h"
15 #include "extensions/browser/extension_system.h" 14 #include "extensions/browser/extension_system.h"
16 #include "extensions/common/api/messaging/message.h"
17 #include "extensions/common/extension_messages.h"
18 #include "extensions/common/extension_urls.h" 15 #include "extensions/common/extension_urls.h"
19 16
20 using content::BrowserContext; 17 using content::BrowserContext;
21 18
22 DEFINE_WEB_CONTENTS_USER_DATA_KEY( 19 DEFINE_WEB_CONTENTS_USER_DATA_KEY(
23 extensions::ChromeExtensionWebContentsObserver); 20 extensions::ChromeExtensionWebContentsObserver);
24 21
25 namespace extensions { 22 namespace extensions {
26 23
27 ChromeExtensionWebContentsObserver::ChromeExtensionWebContentsObserver( 24 ChromeExtensionWebContentsObserver::ChromeExtensionWebContentsObserver(
28 content::WebContents* web_contents) 25 content::WebContents* web_contents)
29 : ExtensionWebContentsObserver(web_contents) {} 26 : ExtensionWebContentsObserver(web_contents) {}
30 27
31 ChromeExtensionWebContentsObserver::~ChromeExtensionWebContentsObserver() {} 28 ChromeExtensionWebContentsObserver::~ChromeExtensionWebContentsObserver() {}
32 29
33 void ChromeExtensionWebContentsObserver::RenderViewCreated( 30 void ChromeExtensionWebContentsObserver::RenderViewCreated(
34 content::RenderViewHost* render_view_host) { 31 content::RenderViewHost* render_view_host) {
35 ReloadIfTerminated(render_view_host); 32 ReloadIfTerminated(render_view_host);
36 ExtensionWebContentsObserver::RenderViewCreated(render_view_host); 33 ExtensionWebContentsObserver::RenderViewCreated(render_view_host);
37 } 34 }
38 35
39 bool ChromeExtensionWebContentsObserver::OnMessageReceived( 36 bool ChromeExtensionWebContentsObserver::OnMessageReceived(
40 const IPC::Message& message) {
41 bool handled = true;
42 IPC_BEGIN_MESSAGE_MAP(ChromeExtensionWebContentsObserver, message)
43 IPC_MESSAGE_HANDLER(ExtensionHostMsg_PostMessage, OnPostMessage)
44 IPC_MESSAGE_UNHANDLED(handled = false)
45 IPC_END_MESSAGE_MAP()
46 return handled;
47 }
48
49 bool ChromeExtensionWebContentsObserver::OnMessageReceived(
50 const IPC::Message& message, 37 const IPC::Message& message,
51 content::RenderFrameHost* render_frame_host) { 38 content::RenderFrameHost* render_frame_host) {
52 #if defined(ENABLE_EXTENSIONS) 39 #if defined(ENABLE_EXTENSIONS)
53 bool handled = true; 40 bool handled = true;
54 IPC_BEGIN_MESSAGE_MAP(ChromeExtensionWebContentsObserver, message) 41 IPC_BEGIN_MESSAGE_MAP(ChromeExtensionWebContentsObserver, message)
55 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DetailedConsoleMessageAdded, 42 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DetailedConsoleMessageAdded,
56 OnDetailedConsoleMessageAdded) 43 OnDetailedConsoleMessageAdded)
57 IPC_MESSAGE_UNHANDLED(handled = false) 44 IPC_MESSAGE_UNHANDLED(handled = false)
58 IPC_END_MESSAGE_MAP() 45 IPC_END_MESSAGE_MAP()
59 #else 46 #else
(...skipping 24 matching lines...) Expand all
84 source, 71 source,
85 message, 72 message,
86 stack_trace, 73 stack_trace,
87 web_contents()->GetLastCommittedURL(), 74 web_contents()->GetLastCommittedURL(),
88 static_cast<logging::LogSeverity>(severity_level), 75 static_cast<logging::LogSeverity>(severity_level),
89 render_view_host->GetRoutingID(), 76 render_view_host->GetRoutingID(),
90 render_view_host->GetProcess()->GetID()))); 77 render_view_host->GetProcess()->GetID())));
91 #endif 78 #endif
92 } 79 }
93 80
94 void ChromeExtensionWebContentsObserver::OnPostMessage(int port_id,
95 const Message& message) {
96 MessageService* message_service = MessageService::Get(browser_context());
97 if (message_service) {
98 message_service->PostMessage(port_id, message);
99 }
100 }
101
102 void ChromeExtensionWebContentsObserver::ReloadIfTerminated( 81 void ChromeExtensionWebContentsObserver::ReloadIfTerminated(
103 content::RenderViewHost* render_view_host) { 82 content::RenderViewHost* render_view_host) {
104 std::string extension_id = GetExtensionId(render_view_host); 83 std::string extension_id = GetExtensionId(render_view_host);
105 if (extension_id.empty()) 84 if (extension_id.empty())
106 return; 85 return;
107 86
108 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context()); 87 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context());
109 88
110 // Reload the extension if it has crashed. 89 // Reload the extension if it has crashed.
111 // TODO(yoz): This reload doesn't happen synchronously for unpacked 90 // TODO(yoz): This reload doesn't happen synchronously for unpacked
112 // extensions. It seems to be fast enough, but there is a race. 91 // extensions. It seems to be fast enough, but there is a race.
113 // We should delay loading until the extension has reloaded. 92 // We should delay loading until the extension has reloaded.
114 if (registry->GetExtensionById(extension_id, ExtensionRegistry::TERMINATED)) { 93 if (registry->GetExtensionById(extension_id, ExtensionRegistry::TERMINATED)) {
115 ExtensionSystem::Get(browser_context())-> 94 ExtensionSystem::Get(browser_context())->
116 extension_service()->ReloadExtension(extension_id); 95 extension_service()->ReloadExtension(extension_id);
117 } 96 }
118 } 97 }
119 98
120 } // namespace extensions 99 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698