OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 #ifndef EXTENSIONS_COMMON_CONSUMER_H_ |
| 6 #define EXTENSIONS_COMMON_CONSUMER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/macros.h" |
| 11 |
| 12 // The type of a host who contains regular tabs or <webview>s. |
| 13 enum HostType { EXTENSIONS, WEBUI }; |
| 14 |
| 15 enum InstanceType { TAB, WEBVIEW }; |
| 16 |
| 17 // IDs of API consumers who own user scripts. |
| 18 // For example: an extension, a <webview> created by an extension, |
| 19 // a <webview> created by WebUI, ... |
| 20 struct ConsumerID { |
| 21 // Default instance ID of a consumer who owns staticlly-defined user scripts. |
| 22 static const int kDefaultInstanceID; |
| 23 |
| 24 ConsumerID(); |
| 25 ConsumerID(HostType host_type, |
| 26 const std::string& host_id, |
| 27 InstanceType instance_type, |
| 28 int instance_id); |
| 29 |
| 30 bool operator<(const ConsumerID& id) const; |
| 31 |
| 32 // Extension, or WebUI, ... |
| 33 HostType host_type; |
| 34 // Similar to extension_id, host_id is a uniquely indentifier for a host, |
| 35 // e.g., an Extension or WebUI. |
| 36 std::string host_id; |
| 37 // A tab or a <webiew> |
| 38 InstanceType instance_type; |
| 39 // For a consumer who owns staticlly-defined user scripts, the |
| 40 // |instance_id| = 0; |
| 41 // For a consumer who owns declarative user scripts, the |instance_id| |
| 42 // is assigned by DeclarativeUserScriptManager when the consumer requests a |
| 43 // master object. |
| 44 int instance_id; |
| 45 }; |
| 46 |
| 47 // Represents an API consumer. |
| 48 class Consumer { |
| 49 public: |
| 50 Consumer(); |
| 51 virtual ~Consumer(); |
| 52 |
| 53 void set_id(ConsumerID id) { id_ = id; } |
| 54 ConsumerID id() { return id_; } |
| 55 |
| 56 private: |
| 57 ConsumerID id_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(Consumer); |
| 60 }; |
| 61 |
| 62 #endif // EXTENSIONS_COMMON_CONSUMER_H_ |
OLD | NEW |