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

Side by Side Diff: chrome/common/custom_handlers/protocol_handler.cc

Issue 267103002: Ignore title parameter for navigator.registerProtocolHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests Created 6 years, 7 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 | Annotate | Revision Log
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/common/custom_handlers/protocol_handler.h" 5 #include "chrome/common/custom_handlers/protocol_handler.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "net/base/escape.h" 9 #include "net/base/escape.h"
10 10
11 11
12 ProtocolHandler::ProtocolHandler(const std::string& protocol, 12 ProtocolHandler::ProtocolHandler(const std::string& protocol,
13 const GURL& url, 13 const GURL& url)
14 const base::string16& title)
15 : protocol_(protocol), 14 : protocol_(protocol),
16 url_(url), 15 url_(url) {
17 title_(title) {
18 } 16 }
19 17
20 ProtocolHandler ProtocolHandler::CreateProtocolHandler( 18 ProtocolHandler ProtocolHandler::CreateProtocolHandler(
21 const std::string& protocol, 19 const std::string& protocol,
22 const GURL& url, 20 const GURL& url) {
23 const base::string16& title) {
24 std::string lower_protocol = StringToLowerASCII(protocol); 21 std::string lower_protocol = StringToLowerASCII(protocol);
25 return ProtocolHandler(lower_protocol, url, title); 22 return ProtocolHandler(lower_protocol, url);
26 } 23 }
27 24
28 ProtocolHandler::ProtocolHandler() { 25 ProtocolHandler::ProtocolHandler() {
29 } 26 }
30 27
31 bool ProtocolHandler::IsValidDict(const base::DictionaryValue* value) { 28 bool ProtocolHandler::IsValidDict(const base::DictionaryValue* value) {
32 return value->HasKey("protocol") && value->HasKey("url") && 29 // Note that "title" parameter is ignored.
33 value->HasKey("title"); 30 return value->HasKey("protocol") && value->HasKey("url");
34 } 31 }
35 32
36 bool ProtocolHandler::IsSameOrigin( 33 bool ProtocolHandler::IsSameOrigin(
37 const ProtocolHandler& handler) const { 34 const ProtocolHandler& handler) const {
38 return handler.url().GetOrigin() == url_.GetOrigin(); 35 return handler.url().GetOrigin() == url_.GetOrigin();
39 } 36 }
40 37
41 const ProtocolHandler& ProtocolHandler::EmptyProtocolHandler() { 38 const ProtocolHandler& ProtocolHandler::EmptyProtocolHandler() {
42 static const ProtocolHandler* const kEmpty = new ProtocolHandler(); 39 static const ProtocolHandler* const kEmpty = new ProtocolHandler();
43 return *kEmpty; 40 return *kEmpty;
44 } 41 }
45 42
46 ProtocolHandler ProtocolHandler::CreateProtocolHandler( 43 ProtocolHandler ProtocolHandler::CreateProtocolHandler(
47 const base::DictionaryValue* value) { 44 const base::DictionaryValue* value) {
48 if (!IsValidDict(value)) { 45 if (!IsValidDict(value)) {
49 return EmptyProtocolHandler(); 46 return EmptyProtocolHandler();
50 } 47 }
51 std::string protocol, url; 48 std::string protocol, url;
52 base::string16 title;
53 value->GetString("protocol", &protocol); 49 value->GetString("protocol", &protocol);
54 value->GetString("url", &url); 50 value->GetString("url", &url);
55 value->GetString("title", &title); 51 return ProtocolHandler::CreateProtocolHandler(protocol, GURL(url));
56 return ProtocolHandler::CreateProtocolHandler(protocol, GURL(url), title);
57 } 52 }
58 53
59 GURL ProtocolHandler::TranslateUrl(const GURL& url) const { 54 GURL ProtocolHandler::TranslateUrl(const GURL& url) const {
60 std::string translatedUrlSpec(url_.spec()); 55 std::string translatedUrlSpec(url_.spec());
61 ReplaceSubstringsAfterOffset(&translatedUrlSpec, 0, "%s", 56 ReplaceSubstringsAfterOffset(&translatedUrlSpec, 0, "%s",
62 net::EscapeQueryParamValue(url.spec(), true)); 57 net::EscapeQueryParamValue(url.spec(), true));
63 return GURL(translatedUrlSpec); 58 return GURL(translatedUrlSpec);
64 } 59 }
65 60
66 base::DictionaryValue* ProtocolHandler::Encode() const { 61 base::DictionaryValue* ProtocolHandler::Encode() const {
67 base::DictionaryValue* d = new base::DictionaryValue(); 62 base::DictionaryValue* d = new base::DictionaryValue();
68 d->Set("protocol", new base::StringValue(protocol_)); 63 d->Set("protocol", new base::StringValue(protocol_));
69 d->Set("url", new base::StringValue(url_.spec())); 64 d->Set("url", new base::StringValue(url_.spec()));
70 d->Set("title", new base::StringValue(title_));
71 return d; 65 return d;
72 } 66 }
73 67
74 #if !defined(NDEBUG) 68 #if !defined(NDEBUG)
75 std::string ProtocolHandler::ToString() const { 69 std::string ProtocolHandler::ToString() const {
76 return "{ protocol=" + protocol_ + 70 return "{ protocol=" + protocol_ +
77 ", url=" + url_.spec() + 71 ", url=" + url_.spec() +
78 ", title=" + base::UTF16ToASCII(title_) +
79 " }"; 72 " }";
80 } 73 }
81 #endif 74 #endif
82 75
83 bool ProtocolHandler::operator==(const ProtocolHandler& other) const { 76 bool ProtocolHandler::operator==(const ProtocolHandler& other) const {
84 return protocol_ == other.protocol_ && 77 return protocol_ == other.protocol_ && url_ == other.url_;
85 url_ == other.url_ &&
86 title_ == other.title_;
87 } 78 }
88 79
89 bool ProtocolHandler::IsEquivalent(const ProtocolHandler& other) const { 80 bool ProtocolHandler::IsEquivalent(const ProtocolHandler& other) const {
90 return protocol_ == other.protocol_ && url_ == other.url_; 81 return protocol_ == other.protocol_ && url_ == other.url_;
91 } 82 }
92 83
93 bool ProtocolHandler::operator<(const ProtocolHandler& other) const { 84 bool ProtocolHandler::operator<(const ProtocolHandler& other) const {
94 return title_ < other.title_; 85 return url_ < other.url_;
95 } 86 }
OLDNEW
« no previous file with comments | « chrome/common/custom_handlers/protocol_handler.h ('k') | content/browser/web_contents/web_contents_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698