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

Side by Side Diff: chrome/renderer/chrome_content_renderer_client.cc

Issue 2228623002: Adding Android specific behavior when overriding YouTube Flash embeds. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@metrics_v2
Patch Set: Addressed comments Created 4 years, 4 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
« no previous file with comments | « no previous file | chrome/renderer/chrome_content_renderer_client_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/renderer/chrome_content_renderer_client.h" 5 #include "chrome/renderer/chrome_content_renderer_client.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 1403 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 1414
1415 // We'll only modify YouTube Flash embeds. The URLs can be recognized since 1415 // We'll only modify YouTube Flash embeds. The URLs can be recognized since
1416 // they're in the following form: youtube.com/v/VIDEO_ID. So, we check to see 1416 // they're in the following form: youtube.com/v/VIDEO_ID. So, we check to see
1417 // if the given URL does follow that format. 1417 // if the given URL does follow that format.
1418 if (!url.DomainIs("youtube.com") && !url.DomainIs("youtube-nocookie.com")) 1418 if (!url.DomainIs("youtube.com") && !url.DomainIs("youtube-nocookie.com"))
1419 return GURL(); 1419 return GURL();
1420 if (url.path().find("/v/") != 0) 1420 if (url.path().find("/v/") != 0)
1421 return GURL(); 1421 return GURL();
1422 1422
1423 std::string url_str = url.spec(); 1423 std::string url_str = url.spec();
1424 internal::YouTubeRewriteStatus result = internal::NUM_PLUGIN_ERROR;
1424 1425
1425 // If the website is using an invalid YouTube URL, we'll try and 1426 // If the website is using an invalid YouTube URL, we'll try and
1426 // fix the URL by ensuring that if there are multiple parameters, 1427 // fix the URL by ensuring that if there are multiple parameters,
1427 // the parameter string begins with a "?" and then follows with a "&" 1428 // the parameter string begins with a "?" and then follows with a "&"
1428 // for each subsequent parameter. We do this because the Flash video player 1429 // for each subsequent parameter. We do this because the Flash video player
1429 // has some URL correction capabilities so we don't want this move to HTML5 1430 // has some URL correction capabilities so we don't want this move to HTML5
1430 // to break webpages that used to work. 1431 // to break webpages that used to work.
1431 size_t index = url_str.find_first_of("&?"); 1432 size_t index = url_str.find_first_of("&?");
1432 bool invalid_url = index != std::string::npos && url_str.at(index) == '&'; 1433 bool invalid_url = index != std::string::npos && url_str.at(index) == '&';
1433 1434
1434 if (invalid_url) { 1435 if (invalid_url) {
1435 // ? should appear first before all parameters 1436 // ? should appear first before all parameters
1436 url_str.replace(index, 1, "?"); 1437 url_str.replace(index, 1, "?");
1437 1438
1438 // Replace all instances of ? (after the first) with & 1439 // Replace all instances of ? (after the first) with &
1439 for (size_t pos = index + 1; 1440 for (size_t pos = index + 1;
1440 (pos = url_str.find("?", pos)) != std::string::npos; pos += 1) { 1441 (pos = url_str.find("?", pos)) != std::string::npos; pos += 1) {
1441 url_str.replace(pos, 1, "&"); 1442 url_str.replace(pos, 1, "&");
1442 } 1443 }
1443 } 1444 }
1444 1445
1445 GURL corrected_url = GURL(url_str); 1446 GURL corrected_url = GURL(url_str);
1446 1447 // Unless we're on an Android device, we don't modify any URLs that contain
1447 // We don't modify any URLs that contain the enablejsapi=1 parameter 1448 // the enablejsapi=1 parameter since the page may be interacting with the
1448 // since the page may be interacting with the YouTube Flash player in 1449 // YouTube Flash player in Javascript and we don't want to break working
1449 // Javascript and we don't want to break working content. 1450 // content. If we're on an Android device and the URL contains the
1451 // enablejsapi=1 parameter, we do override the URL.
1450 if (corrected_url.query().find("enablejsapi=1") != std::string::npos) { 1452 if (corrected_url.query().find("enablejsapi=1") != std::string::npos) {
1453 #if defined(OS_ANDROID)
1454 result = internal::SUCCESS_ENABLEJSAPI;
1455 #else
1451 RecordYouTubeRewriteUMA(internal::FAILURE_ENABLEJSAPI); 1456 RecordYouTubeRewriteUMA(internal::FAILURE_ENABLEJSAPI);
1452 return GURL(); 1457 return GURL();
1458 #endif
1453 } 1459 }
1454 1460
1455 // Change the path to use the YouTube HTML5 API 1461 // Change the path to use the YouTube HTML5 API
1456 std::string path = corrected_url.path(); 1462 std::string path = corrected_url.path();
1457 path.replace(path.find("/v/"), 3, "/embed/"); 1463 path.replace(path.find("/v/"), 3, "/embed/");
1458 1464
1459 url::Replacements<char> r; 1465 url::Replacements<char> r;
1460 r.SetPath(path.c_str(), url::Component(0, path.length())); 1466 r.SetPath(path.c_str(), url::Component(0, path.length()));
1461 1467
1462 RecordYouTubeRewriteUMA(invalid_url ? internal::SUCCESS_PARAMS_REWRITE 1468 if (result == internal::NUM_PLUGIN_ERROR)
1463 : internal::SUCCESS); 1469 result = invalid_url ? internal::SUCCESS_PARAMS_REWRITE : internal::SUCCESS;
1470
1471 RecordYouTubeRewriteUMA(result);
1464 return corrected_url.ReplaceComponents(r); 1472 return corrected_url.ReplaceComponents(r);
1465 } 1473 }
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/chrome_content_renderer_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698