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

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

Issue 6410115: Adds navigator.registerProtocolHandler. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Sync'd, disallow non-same origin rph, adds hostname to the infobar. Created 9 years, 10 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
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/custom_handlers/protocol_handler.h"
6
7 #include "base/string_util.h"
8 #include "net/base/escape.h"
9
10 ProtocolHandler::ProtocolHandler(const std::string& protocol,
11 const GURL& url,
12 const string16& title)
13 : protocol_(protocol),
14 url_(url),
15 title_(title) {
16 }
17
18 ProtocolHandler* ProtocolHandler::CreateProtocolHandler(
19 const std::string& protocol,
20 const GURL& url,
21 const string16& title) {
22 std::string lower_protocol(protocol);
23 lower_protocol = StringToLowerASCII(protocol);
24 return new ProtocolHandler(lower_protocol, url, title);
25 }
26
27 ProtocolHandler* ProtocolHandler::CreateProtocolHandler(
28 const DictionaryValue* value) {
29 std::string protocol, url;
30 string16 title;
31 value->GetString("protocol", &protocol);
32 value->GetString("url", &url);
33 value->GetString("title", &title);
34 return ProtocolHandler::CreateProtocolHandler(protocol, GURL(url), title);
35 }
36
37 GURL ProtocolHandler::TranslateUrl(const GURL& url) {
38 std::string translatedUrlSpec(url_.spec());
39 ReplaceSubstringsAfterOffset(&translatedUrlSpec, 0, "%s",
40 EscapeQueryParamValue(url.spec(), true));
41 return GURL(translatedUrlSpec);
42 }
43
44 Value* ProtocolHandler::Encode() {
45 DictionaryValue* d = new DictionaryValue();
46 d->Set("protocol", Value::CreateStringValue(protocol_));
47 d->Set("url", Value::CreateStringValue(url_.spec()));
48 d->Set("title", Value::CreateStringValue(title_));
49 return d;
50 }
51
52 bool ProtocolHandler::operator==(const ProtocolHandler &other) const {
53 return protocol_ == other.protocol_ &&
54 url_ == other.url_ &&
55 title_ == other.title_;
56 }
57
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698