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 "content/public/browser/notification_source.h" | 8 #include "content/public/browser/notification_source.h" |
9 #include "content/public/browser/notification_types.h" | 9 #include "content/public/browser/notification_types.h" |
10 #include "content/public/browser/render_frame_host.h" | 10 #include "content/public/browser/render_frame_host.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 function_(function) { | 127 function_(function) { |
128 } | 128 } |
129 | 129 |
130 private: | 130 private: |
131 // content::WebContentsObserver: | 131 // content::WebContentsObserver: |
132 virtual void RenderViewDeleted( | 132 virtual void RenderViewDeleted( |
133 content::RenderViewHost* render_view_host) OVERRIDE { | 133 content::RenderViewHost* render_view_host) OVERRIDE { |
134 if (render_view_host != function_->render_view_host()) | 134 if (render_view_host != function_->render_view_host()) |
135 return; | 135 return; |
136 | 136 |
137 function_->SetRenderViewHost(NULL); | 137 function_->SetRenderViewHost(nullptr); |
138 } | 138 } |
139 virtual void RenderFrameDeleted( | 139 virtual void RenderFrameDeleted( |
140 content::RenderFrameHost* render_frame_host) OVERRIDE { | 140 content::RenderFrameHost* render_frame_host) OVERRIDE { |
141 if (render_frame_host != function_->render_frame_host()) | 141 if (render_frame_host != function_->render_frame_host()) |
142 return; | 142 return; |
143 | 143 |
144 function_->SetRenderFrameHost(NULL); | 144 function_->SetRenderFrameHost(nullptr); |
145 } | 145 } |
146 | 146 |
147 virtual bool OnMessageReceived( | 147 virtual bool OnMessageReceived( |
148 const IPC::Message& message, | 148 const IPC::Message& message, |
149 content::RenderFrameHost* render_frame_host) OVERRIDE { | 149 content::RenderFrameHost* render_frame_host) OVERRIDE { |
150 DCHECK(render_frame_host); | 150 DCHECK(render_frame_host); |
151 if (render_frame_host == function_->render_frame_host()) | 151 if (render_frame_host == function_->render_frame_host()) |
152 return function_->OnMessageReceived(message); | 152 return function_->OnMessageReceived(message); |
153 else | 153 else |
154 return false; | 154 return false; |
155 } | 155 } |
156 | 156 |
157 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 157 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { |
158 return function_->OnMessageReceived(message); | 158 return function_->OnMessageReceived(message); |
159 } | 159 } |
160 | 160 |
161 UIThreadExtensionFunction* function_; | 161 UIThreadExtensionFunction* function_; |
162 | 162 |
163 DISALLOW_COPY_AND_ASSIGN(RenderHostTracker); | 163 DISALLOW_COPY_AND_ASSIGN(RenderHostTracker); |
164 }; | 164 }; |
165 | 165 |
166 ExtensionFunction::ExtensionFunction() | 166 ExtensionFunction::ExtensionFunction() |
167 : request_id_(-1), | 167 : request_id_(-1), |
168 profile_id_(NULL), | 168 profile_id_(nullptr), |
169 has_callback_(false), | 169 has_callback_(false), |
170 include_incognito_(false), | 170 include_incognito_(false), |
171 user_gesture_(false), | 171 user_gesture_(false), |
172 bad_message_(false), | 172 bad_message_(false), |
173 histogram_value_(extensions::functions::UNKNOWN), | 173 histogram_value_(extensions::functions::UNKNOWN), |
174 source_tab_id_(-1), | 174 source_tab_id_(-1), |
175 source_context_type_(Feature::UNSPECIFIED_CONTEXT) { | 175 source_context_type_(Feature::UNSPECIFIED_CONTEXT) { |
176 } | 176 } |
177 | 177 |
178 ExtensionFunction::~ExtensionFunction() { | 178 ExtensionFunction::~ExtensionFunction() { |
179 } | 179 } |
180 | 180 |
181 UIThreadExtensionFunction* ExtensionFunction::AsUIThreadExtensionFunction() { | 181 UIThreadExtensionFunction* ExtensionFunction::AsUIThreadExtensionFunction() { |
182 return NULL; | 182 return nullptr; |
183 } | 183 } |
184 | 184 |
185 IOThreadExtensionFunction* ExtensionFunction::AsIOThreadExtensionFunction() { | 185 IOThreadExtensionFunction* ExtensionFunction::AsIOThreadExtensionFunction() { |
186 return NULL; | 186 return nullptr; |
187 } | 187 } |
188 | 188 |
189 bool ExtensionFunction::HasPermission() { | 189 bool ExtensionFunction::HasPermission() { |
190 Feature::Availability availability = | 190 Feature::Availability availability = |
191 ExtensionAPI::GetSharedInstance()->IsAvailable( | 191 ExtensionAPI::GetSharedInstance()->IsAvailable( |
192 name_, extension_.get(), source_context_type_, source_url()); | 192 name_, extension_.get(), source_context_type_, source_url()); |
193 return availability.is_available(); | 193 return availability.is_available(); |
194 } | 194 } |
195 | 195 |
196 void ExtensionFunction::OnQuotaExceeded(const std::string& violation_error) { | 196 void ExtensionFunction::OnQuotaExceeded(const std::string& violation_error) { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 results_.reset(new base::ListValue()); | 329 results_.reset(new base::ListValue()); |
330 | 330 |
331 response_callback_.Run(type, *results_, GetError()); | 331 response_callback_.Run(type, *results_, GetError()); |
332 } | 332 } |
333 | 333 |
334 void ExtensionFunction::OnRespondingLater(ResponseValue value) { | 334 void ExtensionFunction::OnRespondingLater(ResponseValue value) { |
335 SendResponse(value->Apply()); | 335 SendResponse(value->Apply()); |
336 } | 336 } |
337 | 337 |
338 UIThreadExtensionFunction::UIThreadExtensionFunction() | 338 UIThreadExtensionFunction::UIThreadExtensionFunction() |
339 : render_view_host_(NULL), | 339 : render_view_host_(nullptr), |
340 render_frame_host_(NULL), | 340 render_frame_host_(nullptr), |
341 context_(NULL), | 341 context_(nullptr), |
342 delegate_(NULL) { | 342 delegate_(nullptr) { |
343 } | 343 } |
344 | 344 |
345 UIThreadExtensionFunction::~UIThreadExtensionFunction() { | 345 UIThreadExtensionFunction::~UIThreadExtensionFunction() { |
346 if (dispatcher() && render_view_host()) | 346 if (dispatcher() && render_view_host()) |
347 dispatcher()->OnExtensionFunctionCompleted(extension()); | 347 dispatcher()->OnExtensionFunctionCompleted(extension()); |
348 } | 348 } |
349 | 349 |
350 UIThreadExtensionFunction* | 350 UIThreadExtensionFunction* |
351 UIThreadExtensionFunction::AsUIThreadExtensionFunction() { | 351 UIThreadExtensionFunction::AsUIThreadExtensionFunction() { |
352 return this; | 352 return this; |
353 } | 353 } |
354 | 354 |
355 bool UIThreadExtensionFunction::OnMessageReceived(const IPC::Message& message) { | 355 bool UIThreadExtensionFunction::OnMessageReceived(const IPC::Message& message) { |
356 return false; | 356 return false; |
357 } | 357 } |
358 | 358 |
359 void UIThreadExtensionFunction::Destruct() const { | 359 void UIThreadExtensionFunction::Destruct() const { |
360 BrowserThread::DeleteOnUIThread::Destruct(this); | 360 BrowserThread::DeleteOnUIThread::Destruct(this); |
361 } | 361 } |
362 | 362 |
363 void UIThreadExtensionFunction::SetRenderViewHost( | 363 void UIThreadExtensionFunction::SetRenderViewHost( |
364 RenderViewHost* render_view_host) { | 364 RenderViewHost* render_view_host) { |
365 DCHECK(!render_frame_host_); | 365 DCHECK(!render_frame_host_); |
366 render_view_host_ = render_view_host; | 366 render_view_host_ = render_view_host; |
367 tracker_.reset(render_view_host ? new RenderHostTracker(this) : NULL); | 367 tracker_.reset(render_view_host ? new RenderHostTracker(this) : nullptr); |
368 } | 368 } |
369 | 369 |
370 void UIThreadExtensionFunction::SetRenderFrameHost( | 370 void UIThreadExtensionFunction::SetRenderFrameHost( |
371 content::RenderFrameHost* render_frame_host) { | 371 content::RenderFrameHost* render_frame_host) { |
372 DCHECK(!render_view_host_); | 372 DCHECK(!render_view_host_); |
373 render_frame_host_ = render_frame_host; | 373 render_frame_host_ = render_frame_host; |
374 tracker_.reset(render_frame_host ? new RenderHostTracker(this) : NULL); | 374 tracker_.reset(render_frame_host ? new RenderHostTracker(this) : nullptr); |
375 } | 375 } |
376 | 376 |
377 content::WebContents* UIThreadExtensionFunction::GetAssociatedWebContents() { | 377 content::WebContents* UIThreadExtensionFunction::GetAssociatedWebContents() { |
378 content::WebContents* web_contents = NULL; | 378 content::WebContents* web_contents = nullptr; |
379 if (dispatcher()) | 379 if (dispatcher()) |
380 web_contents = dispatcher()->delegate()->GetAssociatedWebContents(); | 380 web_contents = dispatcher()->delegate()->GetAssociatedWebContents(); |
381 | 381 |
382 return web_contents; | 382 return web_contents; |
383 } | 383 } |
384 | 384 |
385 void UIThreadExtensionFunction::SendResponse(bool success) { | 385 void UIThreadExtensionFunction::SendResponse(bool success) { |
386 if (delegate_) | 386 if (delegate_) |
387 delegate_->OnSendResponse(this, success, bad_message_); | 387 delegate_->OnSendResponse(this, success, bad_message_); |
388 else | 388 else |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 | 481 |
482 ExtensionFunction::ResponseAction SyncIOThreadExtensionFunction::Run() { | 482 ExtensionFunction::ResponseAction SyncIOThreadExtensionFunction::Run() { |
483 return RespondNow(RunSync() ? ArgumentList(results_.Pass()) : Error(error_)); | 483 return RespondNow(RunSync() ? ArgumentList(results_.Pass()) : Error(error_)); |
484 } | 484 } |
485 | 485 |
486 // static | 486 // static |
487 bool SyncIOThreadExtensionFunction::ValidationFailure( | 487 bool SyncIOThreadExtensionFunction::ValidationFailure( |
488 SyncIOThreadExtensionFunction* function) { | 488 SyncIOThreadExtensionFunction* function) { |
489 return false; | 489 return false; |
490 } | 490 } |
OLD | NEW |