OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_function.h" | 5 #include "chrome/browser/extensions/extension_function.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 9 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
36 void UIThreadExtensionFunction::RenderViewHostTracker::Observe( | 36 void UIThreadExtensionFunction::RenderViewHostTracker::Observe( |
37 int type, | 37 int type, |
38 const content::NotificationSource& source, | 38 const content::NotificationSource& source, |
39 const content::NotificationDetails& details) { | 39 const content::NotificationDetails& details) { |
40 CHECK(type == content::NOTIFICATION_RENDER_VIEW_HOST_DELETED); | 40 CHECK(type == content::NOTIFICATION_RENDER_VIEW_HOST_DELETED); |
41 CHECK(content::Source<RenderViewHost>(source).ptr() == | 41 CHECK(content::Source<RenderViewHost>(source).ptr() == |
42 function_->render_view_host()); | 42 function_->render_view_host()); |
43 function_->SetRenderViewHost(NULL); | 43 function_->SetRenderViewHost(NULL); |
44 } | 44 } |
45 | 45 |
46 UIThreadExtensionFunction::ExtensionRenderViewHostObserver:: | |
47 ExtensionRenderViewHostObserver(UIThreadExtensionFunction* function, | |
48 RenderViewHost* render_view_host) | |
49 : RenderViewHostObserver(render_view_host), | |
50 function_(function) { | |
51 } | |
52 | |
53 void UIThreadExtensionFunction::ExtensionRenderViewHostObserver:: | |
54 RenderViewHostDestroyed(RenderViewHost* render_view_host) { | |
55 // Default behavior is to delete this. | |
asargent_no_longer_on_chrome
2011/11/15 18:56:31
This comment is kind of confusing - do you mean th
Jay Civelli
2011/11/18 23:14:32
Yes. Clarified comment.
| |
56 // In our case, we'll be deleted when the UIThreadExtensionFunction containing | |
57 // us goes away. | |
58 } | |
59 | |
60 bool UIThreadExtensionFunction::ExtensionRenderViewHostObserver:: | |
61 OnMessageReceived(const IPC::Message& message) { | |
62 return function_->OnMessageReceivedFromRenderView(message); | |
63 } | |
64 | |
46 ExtensionFunction::ExtensionFunction() | 65 ExtensionFunction::ExtensionFunction() |
47 : request_id_(-1), | 66 : request_id_(-1), |
48 profile_id_(NULL), | 67 profile_id_(NULL), |
49 has_callback_(false), | 68 has_callback_(false), |
50 include_incognito_(false), | 69 include_incognito_(false), |
51 user_gesture_(false), | 70 user_gesture_(false), |
52 args_(NULL), | 71 args_(NULL), |
53 bad_message_(false) { | 72 bad_message_(false) { |
54 } | 73 } |
55 | 74 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 } | 151 } |
133 | 152 |
134 UIThreadExtensionFunction::~UIThreadExtensionFunction() { | 153 UIThreadExtensionFunction::~UIThreadExtensionFunction() { |
135 } | 154 } |
136 | 155 |
137 UIThreadExtensionFunction* | 156 UIThreadExtensionFunction* |
138 UIThreadExtensionFunction::AsUIThreadExtensionFunction() { | 157 UIThreadExtensionFunction::AsUIThreadExtensionFunction() { |
139 return this; | 158 return this; |
140 } | 159 } |
141 | 160 |
161 bool UIThreadExtensionFunction::OnMessageReceivedFromRenderView( | |
162 const IPC::Message& message) { | |
163 return false; | |
164 } | |
165 | |
142 void UIThreadExtensionFunction::Destruct() const { | 166 void UIThreadExtensionFunction::Destruct() const { |
143 BrowserThread::DeleteOnUIThread::Destruct(this); | 167 BrowserThread::DeleteOnUIThread::Destruct(this); |
144 } | 168 } |
145 | 169 |
146 void UIThreadExtensionFunction::SetRenderViewHost( | 170 void UIThreadExtensionFunction::SetRenderViewHost( |
147 RenderViewHost* render_view_host) { | 171 RenderViewHost* render_view_host) { |
148 render_view_host_ = render_view_host; | 172 render_view_host_ = render_view_host; |
173 render_view_host_observer_.reset(render_view_host_ ? | |
174 new ExtensionRenderViewHostObserver(this, render_view_host) : NULL); | |
149 tracker_.reset(render_view_host ? new RenderViewHostTracker(this) : NULL); | 175 tracker_.reset(render_view_host ? new RenderViewHostTracker(this) : NULL); |
150 } | 176 } |
151 | 177 |
152 Browser* UIThreadExtensionFunction::GetCurrentBrowser() { | 178 Browser* UIThreadExtensionFunction::GetCurrentBrowser() { |
153 return dispatcher()->GetCurrentBrowser(render_view_host_, include_incognito_); | 179 return dispatcher()->GetCurrentBrowser(render_view_host_, include_incognito_); |
154 } | 180 } |
155 | 181 |
156 void UIThreadExtensionFunction::SendResponse(bool success) { | 182 void UIThreadExtensionFunction::SendResponse(bool success) { |
157 if (!render_view_host_ || !dispatcher()) | 183 if (!render_view_host_ || !dispatcher()) |
158 return; | 184 return; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 | 231 |
206 SyncIOThreadExtensionFunction::SyncIOThreadExtensionFunction() { | 232 SyncIOThreadExtensionFunction::SyncIOThreadExtensionFunction() { |
207 } | 233 } |
208 | 234 |
209 SyncIOThreadExtensionFunction::~SyncIOThreadExtensionFunction() { | 235 SyncIOThreadExtensionFunction::~SyncIOThreadExtensionFunction() { |
210 } | 236 } |
211 | 237 |
212 void SyncIOThreadExtensionFunction::Run() { | 238 void SyncIOThreadExtensionFunction::Run() { |
213 SendResponse(RunImpl()); | 239 SendResponse(RunImpl()); |
214 } | 240 } |
OLD | NEW |