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

Side by Side Diff: content/browser/loader/buffered_resource_handler.cc

Issue 953793003: Ensuring interception of stream get determined by plugin path before checking mime type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
OLDNEW
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 "content/browser/loader/buffered_resource_handler.h" 5 #include "content/browser/loader/buffered_resource_handler.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 type_hint, &new_type); 290 type_hint, &new_type);
291 291
292 // SniffMimeType() returns false if there is not enough data to determine 292 // SniffMimeType() returns false if there is not enough data to determine
293 // the mime type. However, even if it returns false, it returns a new type 293 // the mime type. However, even if it returns false, it returns a new type
294 // that is probably better than the current one. 294 // that is probably better than the current one.
295 response_->head.mime_type.assign(new_type); 295 response_->head.mime_type.assign(new_type);
296 296
297 return made_final_decision; 297 return made_final_decision;
298 } 298 }
299 299
300 bool BufferedResourceHandler::IsHandledByPlugin(bool* defer, bool* result) {
301 #if defined(ENABLE_PLUGINS)
302 *result = true;
303 bool stale;
304 WebPluginInfo plugin;
305 bool has_plugin = GetSupportingPlugin(&plugin, &stale);
306 if (stale) {
307 // Refresh the plugins asynchronously.
308 plugin_service_->GetPlugins(
309 base::Bind(&BufferedResourceHandler::OnPluginsLoaded,
310 weak_ptr_factory_.GetWeakPtr()));
311 request()->LogBlockedBy("BufferedResourceHandler");
312 *defer = true;
313 return true;
314 }
315
316 if (has_plugin) {
317 if (plugin.type == WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN) {
318 // If it is a MimeHandlerView plugin, intercept the stream.
319 std::string payload;
320 scoped_ptr<ResourceHandler> handler(host_->MaybeInterceptAsStream(
321 plugin.path, request(), response_.get(), &payload));
322 if (handler) {
323 *result = UseAlternateNextHandler(handler.Pass(), payload);
324 return true;
325 }
326 return false;
327 } else {
328 return true;
329 }
330 }
331
332 // If we get here then we should try intercepting the stream for the old
333 // streamsPrivate extensions API. This API is deprecated and should go
334 // away.
mmenke 2015/03/24 14:44:31 nit: Don't use "we" in comments.
raymes 2015/03/25 00:26:32 if execution reaches here
Deepak 2015/03/25 05:43:34 Done.
335 std::string payload;
336 scoped_ptr<ResourceHandler> handler(host_->MaybeInterceptAsStream(
337 base::FilePath(), request(), response_.get(), &payload));
338 if (handler) {
339 *result = UseAlternateNextHandler(handler.Pass(), payload);
raymes 2015/03/25 00:26:32 cancel_request = !UseAlternateNextHandler...
Deepak 2015/03/25 05:43:34 Done.
340 return true;
341 }
342 #endif
343 return false;
344 }
345
300 bool BufferedResourceHandler::SelectNextHandler(bool* defer) { 346 bool BufferedResourceHandler::SelectNextHandler(bool* defer) {
301 DCHECK(!response_->head.mime_type.empty()); 347 DCHECK(!response_->head.mime_type.empty());
302 348
303 ResourceRequestInfoImpl* info = GetRequestInfo(); 349 ResourceRequestInfoImpl* info = GetRequestInfo();
304 const std::string& mime_type = response_->head.mime_type; 350 const std::string& mime_type = response_->head.mime_type;
305 351
306 if (net::IsSupportedCertificateMimeType(mime_type)) { 352 if (net::IsSupportedCertificateMimeType(mime_type)) {
307 // Install certificate file. 353 // Install certificate file.
308 info->set_is_download(true); 354 info->set_is_download(true);
309 scoped_ptr<ResourceHandler> handler( 355 scoped_ptr<ResourceHandler> handler(
310 new CertificateResourceHandler(request())); 356 new CertificateResourceHandler(request()));
311 return UseAlternateNextHandler(handler.Pass(), std::string()); 357 return UseAlternateNextHandler(handler.Pass(), std::string());
312 } 358 }
313 359
314 // Allow requests for object/embed tags to be intercepted as streams. 360 // Allow requests for object/embed tags to be intercepted as streams.
315 if (info->GetResourceType() == content::RESOURCE_TYPE_OBJECT) { 361 if (info->GetResourceType() == content::RESOURCE_TYPE_OBJECT) {
316 DCHECK(!info->allow_download()); 362 DCHECK(!info->allow_download());
317 std::string payload; 363 bool result;
318 scoped_ptr<ResourceHandler> handler( 364 if (IsHandledByPlugin(defer, &result))
319 host_->MaybeInterceptAsStream(request(), response_.get(), &payload)); 365 return result;
raymes 2015/03/25 00:26:32 Probably we should change this to: bool cancel_re
Deepak 2015/03/25 05:43:34 Done.
320 if (handler) {
321 DCHECK(!net::IsSupportedMimeType(mime_type));
322 return UseAlternateNextHandler(handler.Pass(), payload);
323 }
324 } 366 }
325 367
326 if (!info->allow_download()) 368 if (!info->allow_download())
327 return true; 369 return true;
328 370
329 // info->allow_download() == true implies 371 // info->allow_download() == true implies
330 // info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME or 372 // info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME or
331 // info->GetResourceType() == RESOURCE_TYPE_SUB_FRAME. 373 // info->GetResourceType() == RESOURCE_TYPE_SUB_FRAME.
332 DCHECK(info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME || 374 DCHECK(info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME ||
333 info->GetResourceType() == RESOURCE_TYPE_SUB_FRAME); 375 info->GetResourceType() == RESOURCE_TYPE_SUB_FRAME);
334 376
335 bool must_download = MustDownload(); 377 bool must_download = MustDownload();
336 if (!must_download) { 378 if (!must_download) {
337 if (net::IsSupportedMimeType(mime_type)) 379 if (net::IsSupportedMimeType(mime_type))
338 return true; 380 return true;
339 381
340 std::string payload; 382 bool result;
341 scoped_ptr<ResourceHandler> handler( 383 if (IsHandledByPlugin(defer, &result))
342 host_->MaybeInterceptAsStream(request(), response_.get(), &payload)); 384 return result;
343 if (handler) {
344 return UseAlternateNextHandler(handler.Pass(), payload);
345 }
346
347 #if defined(ENABLE_PLUGINS)
348 bool stale;
349 bool has_plugin = HasSupportingPlugin(&stale);
350 if (stale) {
351 // Refresh the plugins asynchronously.
352 plugin_service_->GetPlugins(
353 base::Bind(&BufferedResourceHandler::OnPluginsLoaded,
354 weak_ptr_factory_.GetWeakPtr()));
355 request()->LogBlockedBy("BufferedResourceHandler");
356 *defer = true;
357 return true;
358 }
359 if (has_plugin)
360 return true;
361 #endif
362 } 385 }
363 386
364 // Install download handler 387 // Install download handler
365 info->set_is_download(true); 388 info->set_is_download(true);
366 scoped_ptr<ResourceHandler> handler( 389 scoped_ptr<ResourceHandler> handler(
367 host_->CreateResourceHandlerForDownload( 390 host_->CreateResourceHandlerForDownload(
368 request(), 391 request(),
369 true, // is_content_initiated 392 true, // is_content_initiated
370 must_download, 393 must_download,
371 DownloadItem::kInvalidId, 394 DownloadItem::kInvalidId,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 host_->delegate()->ShouldForceDownloadResource( 491 host_->delegate()->ShouldForceDownloadResource(
469 request()->url(), response_->head.mime_type)) { 492 request()->url(), response_->head.mime_type)) {
470 must_download_ = true; 493 must_download_ = true;
471 } else { 494 } else {
472 must_download_ = false; 495 must_download_ = false;
473 } 496 }
474 497
475 return must_download_; 498 return must_download_;
476 } 499 }
477 500
478 bool BufferedResourceHandler::HasSupportingPlugin(bool* stale) { 501 bool BufferedResourceHandler::GetSupportingPlugin(WebPluginInfo* plugin,
502 bool* stale) {
479 #if defined(ENABLE_PLUGINS) 503 #if defined(ENABLE_PLUGINS)
mmenke 2015/03/24 14:44:32 Can we just wrap this method in this ifdef? We ne
Deepak 2015/03/25 05:43:34 Have made the function inline.
480 ResourceRequestInfoImpl* info = GetRequestInfo(); 504 ResourceRequestInfoImpl* info = GetRequestInfo();
481
482 bool allow_wildcard = false; 505 bool allow_wildcard = false;
483 WebPluginInfo plugin;
484 return plugin_service_->GetPluginInfo( 506 return plugin_service_->GetPluginInfo(
485 info->GetChildID(), info->GetRenderFrameID(), info->GetContext(), 507 info->GetChildID(), info->GetRenderFrameID(), info->GetContext(),
486 request()->url(), GURL(), response_->head.mime_type, allow_wildcard, 508 request()->url(), GURL(), response_->head.mime_type, allow_wildcard,
487 stale, &plugin, NULL); 509 stale, plugin, NULL);
488 #else 510 #else
489 if (stale) 511 if (stale)
490 *stale = false; 512 *stale = false;
491 return false; 513 return false;
492 #endif 514 #endif
493 } 515 }
494 516
495 bool BufferedResourceHandler::CopyReadBufferToNextHandler() { 517 bool BufferedResourceHandler::CopyReadBufferToNextHandler() {
496 if (!read_buffer_.get()) 518 if (!read_buffer_.get())
497 return true; 519 return true;
(...skipping 13 matching lines...) Expand all
511 request()->LogUnblocked(); 533 request()->LogUnblocked();
512 bool defer = false; 534 bool defer = false;
513 if (!ProcessResponse(&defer)) { 535 if (!ProcessResponse(&defer)) {
514 controller()->Cancel(); 536 controller()->Cancel();
515 } else if (!defer) { 537 } else if (!defer) {
516 controller()->Resume(); 538 controller()->Resume();
517 } 539 }
518 } 540 }
519 541
520 } // namespace content 542 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698