| 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 "components/plugins/renderer/mobile_youtube_plugin.h" | 5 #include "components/plugins/renderer/mobile_youtube_plugin.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 using blink::WebPlugin; | 21 using blink::WebPlugin; |
| 22 using blink::WebURLRequest; | 22 using blink::WebURLRequest; |
| 23 | 23 |
| 24 const char* const kSlashVSlash = "/v/"; | 24 const char* const kSlashVSlash = "/v/"; |
| 25 const char* const kSlashESlash = "/e/"; | 25 const char* const kSlashESlash = "/e/"; |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 std::string GetYoutubeVideoId(const blink::WebPluginParams& params) { | 29 std::string GetYoutubeVideoId(const blink::WebPluginParams& params) { |
| 30 GURL url(params.url); | 30 GURL url(params.url); |
| 31 std::string video_id = url.path().substr(strlen(kSlashVSlash)); | 31 base::StringPiece video_id = url.path().substr(strlen(kSlashVSlash)); |
| 32 | 32 |
| 33 // Extract just the video id | 33 // Extract just the video id |
| 34 size_t video_id_end = video_id.find('&'); | 34 size_t video_id_end = video_id.find('&'); |
| 35 if (video_id_end != std::string::npos) | 35 if (video_id_end != std::string::npos) |
| 36 video_id = video_id.substr(0, video_id_end); | 36 video_id = video_id.substr(0, video_id_end); |
| 37 return video_id; | 37 return video_id.as_string(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 std::string HtmlData(const blink::WebPluginParams& params, | 40 std::string HtmlData(const blink::WebPluginParams& params, |
| 41 base::StringPiece template_html) { | 41 base::StringPiece template_html) { |
| 42 base::DictionaryValue values; | 42 base::DictionaryValue values; |
| 43 values.SetString("video_id", GetYoutubeVideoId(params)); | 43 values.SetString("video_id", GetYoutubeVideoId(params)); |
| 44 return webui::GetI18nTemplateHtml(template_html, &values); | 44 return webui::GetI18nTemplateHtml(template_html, &values); |
| 45 } | 45 } |
| 46 | 46 |
| 47 bool IsValidYouTubeVideo(const std::string& path) { | 47 bool IsValidYouTubeVideo(const base::StringPiece& path) { |
| 48 unsigned len = strlen(kSlashVSlash); | 48 unsigned len = strlen(kSlashVSlash); |
| 49 | 49 |
| 50 // check for more than just /v/ or /e/. | 50 // check for more than just /v/ or /e/. |
| 51 if (path.length() <= len) | 51 if (path.length() <= len) |
| 52 return false; | 52 return false; |
| 53 | 53 |
| 54 // Youtube flash url can start with /v/ or /e/. | 54 // Youtube flash url can start with /v/ or /e/. |
| 55 if (!base::StartsWith(path, kSlashVSlash, | 55 if (!base::StartsWith(path, kSlashVSlash, |
| 56 base::CompareCase::INSENSITIVE_ASCII) && | 56 base::CompareCase::INSENSITIVE_ASCII) && |
| 57 !base::StartsWith(path, kSlashESlash, | 57 !base::StartsWith(path, kSlashESlash, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 116 } |
| 117 | 117 |
| 118 gin::ObjectTemplateBuilder MobileYouTubePlugin::GetObjectTemplateBuilder( | 118 gin::ObjectTemplateBuilder MobileYouTubePlugin::GetObjectTemplateBuilder( |
| 119 v8::Isolate* isolate) { | 119 v8::Isolate* isolate) { |
| 120 return gin::Wrappable<MobileYouTubePlugin>::GetObjectTemplateBuilder(isolate) | 120 return gin::Wrappable<MobileYouTubePlugin>::GetObjectTemplateBuilder(isolate) |
| 121 .SetMethod("openYoutubeURL", | 121 .SetMethod("openYoutubeURL", |
| 122 &MobileYouTubePlugin::OpenYoutubeUrlCallback); | 122 &MobileYouTubePlugin::OpenYoutubeUrlCallback); |
| 123 } | 123 } |
| 124 | 124 |
| 125 } // namespace plugins | 125 } // namespace plugins |
| OLD | NEW |