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

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: Remove Host::IsEmpty() and move ExtensionConsumer to extensions/renderer. 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 "extensions/common/permissions/permissions_data.h"
12 #include "url/gurl.h"
13
10 // IDs of hosts who own user scripts. 14 // IDs of hosts who own user scripts.
11 // A HostID is immutable after creation. 15 // A HostID is immutable after creation.
12 struct HostID { 16 struct HostID {
13 enum HostType { EXTENSIONS, WEBUI }; 17 enum HostType { EXTENSIONS, WEBUI };
14 18
15 HostID() {} 19 HostID() {}
16 HostID(HostType type, const std::string& id) 20 HostID(HostType type, const std::string& id)
17 : type_(type), id_(id) {} 21 : type_(type), id_(id) {}
22 HostID(const HostID& host_id)
23 : type_(host_id.type()),
24 id_(host_id.id()) {}
18 25
19 bool operator<(const HostID& host_id) const { 26 bool operator<(const HostID& host_id) const {
20 if (type_ != host_id.type()) 27 if (type_ != host_id.type())
21 return type_ < host_id.type(); 28 return type_ < host_id.type();
22 else if (id_ != host_id.id()) 29 else if (id_ != host_id.id())
23 return id_ < host_id.id(); 30 return id_ < host_id.id();
24 return false; 31 return false;
25 } 32 }
26 33
34 bool operator==(const HostID& host_id) const {
35 return type_ == host_id.type() && id_ == host_id.id();
36 }
37
27 HostType type() const { return type_; } 38 HostType type() const { return type_; }
28 const std::string& id() const { return id_; } 39 const std::string& id() const { return id_; }
29 40
30 private: 41 private:
31 // The type of the host. 42 // The type of the host.
32 HostType type_; 43 HostType type_;
33 44
34 // Similar to extension_id, host_id is a unique indentifier for a host, 45 // Similar to extension_id, host_id is a unique indentifier for a host,
35 // e.g., an Extension or WebUI. 46 // e.g., an Extension or WebUI.
36 std::string id_; 47 std::string id_;
37 }; 48 };
38 49
50 // An interface for all kinds of hosts who own user scripts.
51 class Host {
Devlin 2015/02/09 17:40:24 Can't this also be moved to renderer? And just pu
Devlin 2015/02/09 17:40:24 Having a class named "Host" in the global namespac
Xi Han 2015/02/09 23:28:11 That is true, I will rename it as InjectionHost. I
Xi Han 2015/02/09 23:28:11 Moved to renderer. Just put kDefaultInstanceId in
52 public:
53 // The default id of the instance that host will inject the script.
54 // If the instance is a regular tab, the |instance_id| is 0; if the instance
55 // is <webview>, the |instance_id| is a unique number that is bigger than 0.
56 static const int kDefaultInstanceId;
57
58 Host(const HostID& host_id);
59 virtual ~Host();
60
61 virtual const std::string& GetContentSecurityPolicy() const = 0;
62
63 // The base url for the host.
64 virtual const GURL& url() const = 0;
65
66 // The human-readable name of the host.
67 virtual const std::string name() const = 0;
68
69 // Returns true if the script should execute.
70 virtual extensions::PermissionsData::AccessType CanExecuteOnFrame(
71 const GURL& document_url,
72 const GURL& top_frame_url,
73 int tab_id,
74 bool is_declarative) const = 0;
75
76 const HostID& id() const { return id_; }
77 private:
78 // The ID of the host.
79 HostID id_;
80
81 DISALLOW_COPY_AND_ASSIGN(Host);
82 };
83
39 #endif // EXTENSIONS_COMMON_HOST_ID_H_ 84 #endif // EXTENSIONS_COMMON_HOST_ID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698