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

Side by Side Diff: extensions/common/host_id.h

Issue 885493007: Refactoring: de-couple Extensions from "script injection System" [render side] : 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Devlin@'s comments. Created 5 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #ifndef EXTENSIONS_COMMON_HOST_ID_H_ 5 #ifndef EXTENSIONS_COMMON_HOST_ID_H_
6 #define EXTENSIONS_COMMON_HOST_ID_H_ 6 #define EXTENSIONS_COMMON_HOST_ID_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/macros.h"
11 #include "url/gurl.h"
12
10 // IDs of hosts who own user scripts. 13 // IDs of hosts who own user scripts.
11 // A HostID is immutable after creation. 14 // A HostID is immutable after creation.
12 struct HostID { 15 struct HostID {
13 enum HostType { EXTENSIONS, WEBUI }; 16 enum HostType { EXTENSIONS, WEBUI };
14 17
15 HostID() {} 18 HostID() {}
16 HostID(HostType type, const std::string& id) 19 HostID(HostType type, const std::string& id)
17 : type_(type), id_(id) {} 20 : type_(type), id_(id) {}
21 HostID(const HostID& host_id)
22 : type_(host_id.type()),
23 id_(host_id.id()) {}
18 24
19 bool operator<(const HostID& host_id) const { 25 bool operator<(const HostID& host_id) const {
20 if (type_ != host_id.type()) 26 if (type_ != host_id.type())
21 return type_ < host_id.type(); 27 return type_ < host_id.type();
22 else if (id_ != host_id.id()) 28 else if (id_ != host_id.id())
23 return id_ < host_id.id(); 29 return id_ < host_id.id();
24 return false; 30 return false;
25 } 31 }
26 32
27 HostType type() const { return type_; } 33 HostType type() const { return type_; }
28 const std::string& id() const { return id_; } 34 const std::string& id() const { return id_; }
29 35
30 private: 36 private:
31 // The type of the host. 37 // The type of the host.
32 HostType type_; 38 HostType type_;
33 39
34 // Similar to extension_id, host_id is a unique indentifier for a host, 40 // Similar to extension_id, host_id is a unique indentifier for a host,
35 // e.g., an Extension or WebUI. 41 // e.g., an Extension or WebUI.
36 std::string id_; 42 std::string id_;
37 }; 43 };
38 44
45 // An interface for all kinds of hosts who own user scripts.
46 class Host {
47 public:
48 // The default id of the instance that host will inject the script.
49 // If the instance is a regular tab, the |instance_id| is 0; if the instance
50 // is <webview>, the |instance_id| is a unique number that is bigger than 0.
51 static const int kDefaultInstanceId;
52
53 Host(const HostID& host_id);
54 virtual ~Host();
55
56 // Returns if the Host owns a non-empty pointer to the real host object
57 // (extension, or WebUI).
Devlin 2015/02/06 00:28:41 The idea of a Host being non-null but "empty" is w
Xi Han 2015/02/06 17:21:45 My initial thoughts was we may have a WebUIConsume
Devlin 2015/02/06 18:48:36 Well, all interactions from the script injection s
Xi Han 2015/02/06 19:45:33 That is fair. We can create a Host object for webU
58 virtual bool IsEmpty() const = 0;
59
60 virtual const std::string& GetContentSecurityPolicy() const = 0;
61
62 // The base url for the host.
63 virtual const GURL& url() const = 0;
64
65 // The human-readable name of the host.
66 virtual const std::string name() const = 0;
67
68 const HostID& id() const { return id_; }
69 private:
70 // The ID of the host.
71 HostID id_;
72
73 DISALLOW_COPY_AND_ASSIGN(Host);
74 };
75
39 #endif // EXTENSIONS_COMMON_HOST_ID_H_ 76 #endif // EXTENSIONS_COMMON_HOST_ID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698