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

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: Responded to comments. 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
jam 2011/02/16 18:29:37 nit: extra line
koz (OOO until 15th September) 2011/02/17 03:32:03 Removed, cheers.
11 ProtocolHandler::ProtocolHandler(const std::string& protocol,
12 const GURL& url,
13 const string16& title)
14 : protocol_(protocol),
15 url_(url),
16 title_(title) {
17 }
18
19 ProtocolHandler* ProtocolHandler::CreateProtocolHandler(
20 const std::string& protocol,
21 const GURL& url,
22 const string16& title) {
23 std::string lower_protocol(protocol);
24 lower_protocol = StringToLowerASCII(protocol);
25 return new ProtocolHandler(lower_protocol, url, title);
26 }
27
28 ProtocolHandler* ProtocolHandler::CreateProtocolHandler(
29 const DictionaryValue* value) {
30 std::string protocol, url;
31 string16 title;
32 value->GetString("protocol", &protocol);
33 value->GetString("url", &url);
34 value->GetString("title", &title);
35 return ProtocolHandler::CreateProtocolHandler(protocol, GURL(url), title);
36 }
37
38 GURL ProtocolHandler::TranslateUrl(const GURL& url) {
39 std::string translatedUrlSpec(url_.spec());
40 ReplaceSubstringsAfterOffset(&translatedUrlSpec, 0, "%s",
41 EscapeQueryParamValue(url.spec(), true));
42 return GURL(translatedUrlSpec);
43 }
44
45 Value* ProtocolHandler::Encode() {
46 DictionaryValue* d = new DictionaryValue();
47 d->Set("protocol", Value::CreateStringValue(protocol_));
48 d->Set("url", Value::CreateStringValue(url_.spec()));
49 d->Set("title", Value::CreateStringValue(title_));
50 return d;
51 }
52
53 bool ProtocolHandler::operator==(const ProtocolHandler &other) const {
54 return protocol_ == other.protocol_ &&
55 url_ == other.url_ &&
56 title_ == other.title_;
57 }
58
OLDNEW
« no previous file with comments | « chrome/browser/custom_handlers/protocol_handler.h ('k') | chrome/browser/custom_handlers/protocol_handler_registry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698