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

Side by Side Diff: chrome/browser/extensions/api/messaging/extension_message_port.h

Issue 1966283002: Remove port lifetime management from renderer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify: Assume that opener port is open, only send reply if closed Created 4 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_API_MESSAGING_EXTENSION_MESSAGE_PORT_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MESSAGING_EXTENSION_MESSAGE_PORT_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_EXTENSION_MESSAGE_PORT_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_EXTENSION_MESSAGE_PORT_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "chrome/browser/extensions/api/messaging/message_service.h" 9 #include "chrome/browser/extensions/api/messaging/message_service.h"
10 10
(...skipping 23 matching lines...) Expand all
34 content::RenderFrameHost* rfh, 34 content::RenderFrameHost* rfh,
35 bool include_child_frames); 35 bool include_child_frames);
36 // Create a port that is tied to all frames of an extension, possibly spanning 36 // Create a port that is tied to all frames of an extension, possibly spanning
37 // multiple tabs, including the invisible background page, popups, etc. 37 // multiple tabs, including the invisible background page, popups, etc.
38 ExtensionMessagePort(base::WeakPtr<MessageService> message_service, 38 ExtensionMessagePort(base::WeakPtr<MessageService> message_service,
39 int port_id, 39 int port_id,
40 const std::string& extension_id, 40 const std::string& extension_id,
41 content::RenderProcessHost* extension_process); 41 content::RenderProcessHost* extension_process);
42 ~ExtensionMessagePort() override; 42 ~ExtensionMessagePort() override;
43 43
44 // Check whether the port exists in the frames. Frames that don't know about
Devlin 2016/05/17 19:50:29 nitty nit: descriptive rather than imperative func
Devlin 2016/05/17 19:50:29 Specify "the frames"
robwu 2016/05/17 22:47:50 Done 2x.
45 // the port are removed from the set of frames. This should be used for opener
46 // ports because the frame may be navigated before the port was initialized.
47 void RevalidatePort();
48
44 // MessageService::MessagePort: 49 // MessageService::MessagePort:
45 void RemoveCommonFrames(const MessagePort& port) override; 50 void RemoveCommonFrames(const MessagePort& port) override;
46 bool HasFrame(content::RenderFrameHost* rfh) const override; 51 bool HasFrame(content::RenderFrameHost* rfh) const override;
47 bool IsValidPort() override; 52 bool IsValidPort() override;
48 void DispatchOnConnect(const std::string& channel_name, 53 void DispatchOnConnect(const std::string& channel_name,
49 std::unique_ptr<base::DictionaryValue> source_tab, 54 std::unique_ptr<base::DictionaryValue> source_tab,
50 int source_frame_id, 55 int source_frame_id,
51 int guest_process_id, 56 int guest_process_id,
52 int guest_render_frame_routing_id, 57 int guest_render_frame_routing_id,
53 const std::string& source_extension_id, 58 const std::string& source_extension_id,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // Only for receivers in an extension process. 90 // Only for receivers in an extension process.
86 content::RenderProcessHost* extension_process_; 91 content::RenderProcessHost* extension_process_;
87 92
88 // When the port is used as a sender, this set contains only one element. 93 // When the port is used as a sender, this set contains only one element.
89 // If used as a receiver, it may contain any number of frames. 94 // If used as a receiver, it may contain any number of frames.
90 // This set is populated before the first message is sent to the destination, 95 // This set is populated before the first message is sent to the destination,
91 // and shrinks over time when the port is rejected by the recipient frame, or 96 // and shrinks over time when the port is rejected by the recipient frame, or
92 // when the frame is removed or unloaded. 97 // when the frame is removed or unloaded.
93 std::set<content::RenderFrameHost*> frames_; 98 std::set<content::RenderFrameHost*> frames_;
94 99
100 // The ID of the tab where the channel was created. This is saved so that any
101 // onMessage events can be run in the scope of the tab.
102 // Only set on receiver ports (if the opener was a tab).
Devlin 2016/05/17 19:50:29 Specify that this is -1 if invalid (pretty common,
robwu 2016/05/17 22:47:50 Done.
103 int opener_tab_id_;
104
95 // Whether the renderer acknowledged creation of the port. This is used to 105 // Whether the renderer acknowledged creation of the port. This is used to
96 // distinguish abnormal port closure (e.g. no receivers) from explicit port 106 // distinguish abnormal port closure (e.g. no receivers) from explicit port
97 // closure (e.g. by the port.disconnect() JavaScript method in the renderer). 107 // closure (e.g. by the port.disconnect() JavaScript method in the renderer).
98 bool did_create_port_; 108 bool did_create_port_;
99 109
100 ExtensionHost* background_host_ptr_; // used in IncrementLazyKeepaliveCount 110 ExtensionHost* background_host_ptr_; // used in IncrementLazyKeepaliveCount
101 std::unique_ptr<FrameTracker> frame_tracker_; 111 std::unique_ptr<FrameTracker> frame_tracker_;
102 112
103 DISALLOW_COPY_AND_ASSIGN(ExtensionMessagePort); 113 DISALLOW_COPY_AND_ASSIGN(ExtensionMessagePort);
104 }; 114 };
105 115
106 } // namespace extensions 116 } // namespace extensions
107 117
108 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_EXTENSION_MESSAGE_PORT_H_ 118 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_EXTENSION_MESSAGE_PORT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698