OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/browser/extension_function.h" | 5 #include "extensions/browser/extension_function.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/sparse_histogram.h" | 8 #include "base/metrics/sparse_histogram.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 19 matching lines...) Expand all Loading... |
30 } | 30 } |
31 | 31 |
32 // Helper class to track the lifetime of ExtensionFunction's RenderViewHost or | 32 // Helper class to track the lifetime of ExtensionFunction's RenderViewHost or |
33 // RenderFrameHost pointer and NULL it out when it dies. It also allows us to | 33 // RenderFrameHost pointer and NULL it out when it dies. It also allows us to |
34 // filter IPC messages coming from the RenderViewHost/RenderFrameHost. | 34 // filter IPC messages coming from the RenderViewHost/RenderFrameHost. |
35 class UIThreadExtensionFunction::RenderHostTracker | 35 class UIThreadExtensionFunction::RenderHostTracker |
36 : public content::WebContentsObserver { | 36 : public content::WebContentsObserver { |
37 public: | 37 public: |
38 explicit RenderHostTracker(UIThreadExtensionFunction* function) | 38 explicit RenderHostTracker(UIThreadExtensionFunction* function) |
39 : content::WebContentsObserver( | 39 : content::WebContentsObserver( |
40 function->render_view_host() ? | 40 function->render_view_host() ? |
41 WebContents::FromRenderViewHost(function->render_view_host()) : | 41 WebContents::FromRenderViewHost(function->render_view_host()) : |
42 WebContents::FromRenderFrameHost( | 42 WebContents::FromRenderFrameHost( |
43 function->render_frame_host())), | 43 function->render_frame_host())), |
44 function_(function) { | 44 function_(function) { |
45 } | 45 } |
46 | 46 |
47 private: | 47 private: |
48 // content::WebContentsObserver: | 48 // content::WebContentsObserver: |
49 virtual void RenderViewDeleted( | 49 virtual void RenderViewDeleted( |
50 content::RenderViewHost* render_view_host) OVERRIDE { | 50 content::RenderViewHost* render_view_host) OVERRIDE { |
(...skipping 19 matching lines...) Expand all Loading... |
70 DISALLOW_COPY_AND_ASSIGN(RenderHostTracker); | 70 DISALLOW_COPY_AND_ASSIGN(RenderHostTracker); |
71 }; | 71 }; |
72 | 72 |
73 ExtensionFunction::ExtensionFunction() | 73 ExtensionFunction::ExtensionFunction() |
74 : request_id_(-1), | 74 : request_id_(-1), |
75 profile_id_(NULL), | 75 profile_id_(NULL), |
76 has_callback_(false), | 76 has_callback_(false), |
77 include_incognito_(false), | 77 include_incognito_(false), |
78 user_gesture_(false), | 78 user_gesture_(false), |
79 bad_message_(false), | 79 bad_message_(false), |
80 histogram_value_(extensions::functions::UNKNOWN) {} | 80 histogram_value_(extensions::functions::UNKNOWN), |
| 81 source_tab_id_(-1) { |
| 82 } |
81 | 83 |
82 ExtensionFunction::~ExtensionFunction() { | 84 ExtensionFunction::~ExtensionFunction() { |
83 } | 85 } |
84 | 86 |
85 UIThreadExtensionFunction* ExtensionFunction::AsUIThreadExtensionFunction() { | 87 UIThreadExtensionFunction* ExtensionFunction::AsUIThreadExtensionFunction() { |
86 return NULL; | 88 return NULL; |
87 } | 89 } |
88 | 90 |
89 IOThreadExtensionFunction* ExtensionFunction::AsIOThreadExtensionFunction() { | 91 IOThreadExtensionFunction* ExtensionFunction::AsIOThreadExtensionFunction() { |
90 return NULL; | 92 return NULL; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 } | 152 } |
151 | 153 |
152 // If results were never set, we send an empty argument list. | 154 // If results were never set, we send an empty argument list. |
153 if (!results_) | 155 if (!results_) |
154 results_.reset(new base::ListValue()); | 156 results_.reset(new base::ListValue()); |
155 | 157 |
156 response_callback_.Run(type, *results_, GetError()); | 158 response_callback_.Run(type, *results_, GetError()); |
157 } | 159 } |
158 | 160 |
159 UIThreadExtensionFunction::UIThreadExtensionFunction() | 161 UIThreadExtensionFunction::UIThreadExtensionFunction() |
160 : render_view_host_(NULL), render_frame_host_(NULL), context_(NULL), | 162 : render_view_host_(NULL), |
161 delegate_(NULL) {} | 163 render_frame_host_(NULL), |
| 164 context_(NULL), |
| 165 delegate_(NULL) { |
| 166 } |
162 | 167 |
163 UIThreadExtensionFunction::~UIThreadExtensionFunction() { | 168 UIThreadExtensionFunction::~UIThreadExtensionFunction() { |
164 if (dispatcher() && render_view_host()) | 169 if (dispatcher() && render_view_host()) |
165 dispatcher()->OnExtensionFunctionCompleted(GetExtension()); | 170 dispatcher()->OnExtensionFunctionCompleted(GetExtension()); |
166 } | 171 } |
167 | 172 |
168 UIThreadExtensionFunction* | 173 UIThreadExtensionFunction* |
169 UIThreadExtensionFunction::AsUIThreadExtensionFunction() { | 174 UIThreadExtensionFunction::AsUIThreadExtensionFunction() { |
170 return this; | 175 return this; |
171 } | 176 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 262 |
258 SyncIOThreadExtensionFunction::SyncIOThreadExtensionFunction() { | 263 SyncIOThreadExtensionFunction::SyncIOThreadExtensionFunction() { |
259 } | 264 } |
260 | 265 |
261 SyncIOThreadExtensionFunction::~SyncIOThreadExtensionFunction() { | 266 SyncIOThreadExtensionFunction::~SyncIOThreadExtensionFunction() { |
262 } | 267 } |
263 | 268 |
264 void SyncIOThreadExtensionFunction::Run() { | 269 void SyncIOThreadExtensionFunction::Run() { |
265 SendResponse(RunImpl()); | 270 SendResponse(RunImpl()); |
266 } | 271 } |
OLD | NEW |