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

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
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 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 1409
1410 // We'll only modify YouTube Flash embeds. The URLs can be recognized since 1410 // We'll only modify YouTube Flash embeds. The URLs can be recognized since
1411 // they're in the following form: youtube.com/v/VIDEO_ID. So, we check to see 1411 // they're in the following form: youtube.com/v/VIDEO_ID. So, we check to see
1412 // if the given URL does follow that format. 1412 // if the given URL does follow that format.
1413 if (!url.DomainIs("youtube.com") && !url.DomainIs("youtube-nocookie.com")) 1413 if (!url.DomainIs("youtube.com") && !url.DomainIs("youtube-nocookie.com"))
1414 return GURL(); 1414 return GURL();
1415 if (url.path().find("/v/") != 0) 1415 if (url.path().find("/v/") != 0)
1416 return GURL(); 1416 return GURL();
1417 1417
1418 std::string url_str = url.spec(); 1418 std::string url_str = url.spec();
1419 internal::YouTubeRewriteStatus result = internal::NUM_PLUGIN_ERROR;
1419 1420
1420 // If the website is using an invalid YouTube URL, we'll try and 1421 // If the website is using an invalid YouTube URL, we'll try and
1421 // fix the URL by ensuring that if there are multiple parameters, 1422 // fix the URL by ensuring that if there are multiple parameters,
1422 // the parameter string begins with a "?" and then follows with a "&" 1423 // the parameter string begins with a "?" and then follows with a "&"
1423 // for each subsequent parameter. We do this because the Flash video player 1424 // for each subsequent parameter. We do this because the Flash video player
1424 // has some URL correction capabilities so we don't want this move to HTML5 1425 // has some URL correction capabilities so we don't want this move to HTML5
1425 // to break webpages that used to work. 1426 // to break webpages that used to work.
1426 size_t index = url_str.find_first_of("&?"); 1427 size_t index = url_str.find_first_of("&?");
1427 bool invalid_url = index != std::string::npos && url_str.at(index) == '&'; 1428 bool invalid_url = index != std::string::npos && url_str.at(index) == '&';
1428 1429
1429 if (invalid_url) { 1430 if (invalid_url) {
1430 // ? should appear first before all parameters 1431 // ? should appear first before all parameters
1431 url_str.replace(index, 1, "?"); 1432 url_str.replace(index, 1, "?");
1432 1433
1433 // Replace all instances of ? (after the first) with & 1434 // Replace all instances of ? (after the first) with &
1434 for (size_t pos = index + 1; 1435 for (size_t pos = index + 1;
1435 (pos = url_str.find("?", pos)) != std::string::npos; pos += 1) { 1436 (pos = url_str.find("?", pos)) != std::string::npos; pos += 1) {
1436 url_str.replace(pos, 1, "&"); 1437 url_str.replace(pos, 1, "&");
1437 } 1438 }
1438 } 1439 }
1439 1440
1440 GURL corrected_url = GURL(url_str); 1441 GURL corrected_url = GURL(url_str);
1441 1442 // Unless we're on an Android device, we don't modify any URLs that contain
1442 // We don't modify any URLs that contain the enablejsapi=1 parameter 1443 // the enablejsapi=1 parameter since the page may be interacting with the
1443 // since the page may be interacting with the YouTube Flash player in 1444 // YouTube Flash player in Javascript and we don't want to break working
1444 // Javascript and we don't want to break working content. 1445 // content. If we're on an Android device and the URL contains the
1446 // enablejsapi=1 parameter, we do override the URL.
1445 if (corrected_url.query().find("enablejsapi=1") != std::string::npos) { 1447 if (corrected_url.query().find("enablejsapi=1") != std::string::npos) {
1448 #if defined(OS_ANDROID)
1449 result = internal::SUCCESS_ENABLEJSAPI;
1450 #else
1446 RecordYouTubeRewriteUMA(internal::FAILURE_ENABLEJSAPI); 1451 RecordYouTubeRewriteUMA(internal::FAILURE_ENABLEJSAPI);
1447 return GURL(); 1452 return GURL();
1453 #endif
1448 } 1454 }
1449 1455
1450 // Change the path to use the YouTube HTML5 API 1456 // Change the path to use the YouTube HTML5 API
1451 std::string path = corrected_url.path(); 1457 std::string path = corrected_url.path();
1452 path.replace(path.find("/v/"), 3, "/embed/"); 1458 path.replace(path.find("/v/"), 3, "/embed/");
1453 1459
1454 url::Replacements<char> r; 1460 url::Replacements<char> r;
1455 r.SetPath(path.c_str(), url::Component(0, path.length())); 1461 r.SetPath(path.c_str(), url::Component(0, path.length()));
1456 1462
1457 RecordYouTubeRewriteUMA(invalid_url ? internal::SUCCESS_PARAMS_REWRITE 1463 if (result == internal::NUM_PLUGIN_ERROR)
1458 : internal::SUCCESS); 1464 result = invalid_url ? internal::SUCCESS_PARAMS_REWRITE : internal::SUCCESS;
1465
1466 RecordYouTubeRewriteUMA(result);
1459 return corrected_url.ReplaceComponents(r); 1467 return corrected_url.ReplaceComponents(r);
1460 } 1468 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698