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

Side by Side Diff: components/plugins/renderer/mobile_youtube_plugin.cc

Issue 63273002: Rename WebKit namespace to blink (part 4) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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 "components/plugins/renderer/mobile_youtube_plugin.h" 5 #include "components/plugins/renderer/mobile_youtube_plugin.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/strings/string_piece.h" 9 #include "base/strings/string_piece.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "content/public/common/content_constants.h" 12 #include "content/public/common/content_constants.h"
13 #include "content/public/renderer/render_view.h" 13 #include "content/public/renderer/render_view.h"
14 #include "third_party/WebKit/public/web/WebFrame.h" 14 #include "third_party/WebKit/public/web/WebFrame.h"
15 #include "ui/base/webui/jstemplate_builder.h" 15 #include "ui/base/webui/jstemplate_builder.h"
16 16
17 using WebKit::WebFrame; 17 using blink::WebFrame;
18 using WebKit::WebPlugin; 18 using blink::WebPlugin;
19 using WebKit::WebURLRequest; 19 using blink::WebURLRequest;
20 20
21 const char* const kSlashVSlash = "/v/"; 21 const char* const kSlashVSlash = "/v/";
22 const char* const kSlashESlash = "/e/"; 22 const char* const kSlashESlash = "/e/";
23 23
24 namespace { 24 namespace {
25 25
26 std::string GetYoutubeVideoId(const WebKit::WebPluginParams& params) { 26 std::string GetYoutubeVideoId(const blink::WebPluginParams& params) {
27 GURL url(params.url); 27 GURL url(params.url);
28 std::string video_id = url.path().substr(strlen(kSlashVSlash)); 28 std::string video_id = url.path().substr(strlen(kSlashVSlash));
29 29
30 // Extract just the video id 30 // Extract just the video id
31 size_t video_id_end = video_id.find('&'); 31 size_t video_id_end = video_id.find('&');
32 if (video_id_end != std::string::npos) 32 if (video_id_end != std::string::npos)
33 video_id = video_id.substr(0, video_id_end); 33 video_id = video_id.substr(0, video_id_end);
34 return video_id; 34 return video_id;
35 } 35 }
36 36
37 std::string HtmlData(const WebKit::WebPluginParams& params, 37 std::string HtmlData(const blink::WebPluginParams& params,
38 base::StringPiece template_html) { 38 base::StringPiece template_html) {
39 base::DictionaryValue values; 39 base::DictionaryValue values;
40 values.SetString("video_id", GetYoutubeVideoId(params)); 40 values.SetString("video_id", GetYoutubeVideoId(params));
41 return webui::GetI18nTemplateHtml(template_html, &values); 41 return webui::GetI18nTemplateHtml(template_html, &values);
42 } 42 }
43 43
44 bool IsValidYouTubeVideo(const std::string& path) { 44 bool IsValidYouTubeVideo(const std::string& path) {
45 unsigned len = strlen(kSlashVSlash); 45 unsigned len = strlen(kSlashVSlash);
46 46
47 // check for more than just /v/ or /e/. 47 // check for more than just /v/ or /e/.
(...skipping 16 matching lines...) Expand all
64 return c == '&' && i > len; 64 return c == '&' && i > len;
65 } 65 }
66 return true; 66 return true;
67 } 67 }
68 68
69 } // namespace 69 } // namespace
70 70
71 namespace plugins { 71 namespace plugins {
72 72
73 MobileYouTubePlugin::MobileYouTubePlugin(content::RenderView* render_view, 73 MobileYouTubePlugin::MobileYouTubePlugin(content::RenderView* render_view,
74 WebKit::WebFrame* frame, 74 blink::WebFrame* frame,
75 const WebKit::WebPluginParams& params, 75 const blink::WebPluginParams& params,
76 base::StringPiece& template_html, 76 base::StringPiece& template_html,
77 GURL placeholderDataUrl) 77 GURL placeholderDataUrl)
78 : PluginPlaceholder(render_view, 78 : PluginPlaceholder(render_view,
79 frame, 79 frame,
80 params, 80 params,
81 HtmlData(params, template_html), 81 HtmlData(params, template_html),
82 placeholderDataUrl) {} 82 placeholderDataUrl) {}
83 83
84 // static 84 // static
85 bool MobileYouTubePlugin::IsYouTubeURL(const GURL& url, 85 bool MobileYouTubePlugin::IsYouTubeURL(const GURL& url,
86 const std::string& mime_type) { 86 const std::string& mime_type) {
87 std::string host = url.host(); 87 std::string host = url.host();
88 bool is_youtube = EndsWith(host, "youtube.com", true) || 88 bool is_youtube = EndsWith(host, "youtube.com", true) ||
89 EndsWith(host, "youtube-nocookie.com", true); 89 EndsWith(host, "youtube-nocookie.com", true);
90 90
91 return is_youtube && IsValidYouTubeVideo(url.path()) && 91 return is_youtube && IsValidYouTubeVideo(url.path()) &&
92 LowerCaseEqualsASCII(mime_type, content::kFlashPluginSwfMimeType); 92 LowerCaseEqualsASCII(mime_type, content::kFlashPluginSwfMimeType);
93 } 93 }
94 94
95 void MobileYouTubePlugin::OpenYoutubeUrlCallback( 95 void MobileYouTubePlugin::OpenYoutubeUrlCallback(
96 const webkit_glue::CppArgumentList& args, 96 const webkit_glue::CppArgumentList& args,
97 webkit_glue::CppVariant* result) { 97 webkit_glue::CppVariant* result) {
98 std::string youtube("vnd.youtube:"); 98 std::string youtube("vnd.youtube:");
99 GURL url(youtube.append(GetYoutubeVideoId(GetPluginParams()))); 99 GURL url(youtube.append(GetYoutubeVideoId(GetPluginParams())));
100 WebURLRequest request; 100 WebURLRequest request;
101 request.initialize(); 101 request.initialize();
102 request.setURL(url); 102 request.setURL(url);
103 render_view()->LoadURLExternally( 103 render_view()->LoadURLExternally(
104 GetFrame(), request, WebKit::WebNavigationPolicyNewForegroundTab); 104 GetFrame(), request, blink::WebNavigationPolicyNewForegroundTab);
105 } 105 }
106 void MobileYouTubePlugin::BindWebFrame(WebFrame* frame) { 106 void MobileYouTubePlugin::BindWebFrame(WebFrame* frame) {
107 PluginPlaceholder::BindWebFrame(frame); 107 PluginPlaceholder::BindWebFrame(frame);
108 BindCallback("openYoutubeURL", 108 BindCallback("openYoutubeURL",
109 base::Bind(&MobileYouTubePlugin::OpenYoutubeUrlCallback, 109 base::Bind(&MobileYouTubePlugin::OpenYoutubeUrlCallback,
110 base::Unretained(this))); 110 base::Unretained(this)));
111 } 111 }
112 112
113 } // namespace plugins 113 } // namespace plugins
OLDNEW
« no previous file with comments | « components/plugins/renderer/mobile_youtube_plugin.h ('k') | components/plugins/renderer/plugin_placeholder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698