Skip to content

Commit 8806978

Browse files
Add a permissions model to the Chrome NPAPI plugin.
Permissions are stored in localstorage of the background page. They can be changed by navigating to the extension's options page. A page action indicates if the plugin permissions are good or bad for the current host. Review at http://gwt-code-reviews.appspot.com/1084801 git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9283 8db76d5a-ed1c-0410-87a9-c151d255dfc7
1 parent 3172139 commit 8806978

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1001
-336
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="core/src"/>
4+
<classpathentry kind="src" output="war" path="core/war"/>
5+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
6+
<classpathentry combineaccessrules="false" kind="src" path="/gwt-user"/>
7+
<classpathentry kind="output" path="war/WEB-INF/classes"/>
8+
</classpath>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>DevModeOptions</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>com.google.gwt.eclipse.core.gwtProjectValidator</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>com.google.gwt.eclipse.core.gwtNature</nature>
22+
</natures>
23+
<linkedResources>
24+
<link>
25+
<name>core</name>
26+
<type>2</type>
27+
<locationURI>GWT_ROOT/plugins/npapi/DevModeOptions</locationURI>
28+
</link>
29+
</linkedResources>
30+
</projectDescription>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<project name="DevModeOptions" default="prebuilt" basedir=".">
3+
<!-- Arguments to gwtc and devmode targets -->
4+
<property name="gwt.args" value="" />
5+
6+
<!-- Configure path to GWT SDK -->
7+
<property name="gwt.sdk" location="../../../build/staging/gwt-0.0.0" />
8+
9+
<path id="project.class.path">
10+
<pathelement location="war/WEB-INF/classes"/>
11+
<pathelement location="${gwt.sdk}/gwt-user.jar"/>
12+
<fileset dir="${gwt.sdk}" includes="gwt-dev*.jar"/>
13+
<!-- Add any additional non-server libs (such as JUnit) -->
14+
<fileset dir="war/WEB-INF/lib" includes="**/*.jar"/>
15+
</path>
16+
17+
<target name="javac" description="Compile java source to bytecode">
18+
<mkdir dir="war/WEB-INF/classes"/>
19+
<javac srcdir="src" includes="**" encoding="utf-8"
20+
destdir="war/WEB-INF/classes"
21+
source="1.5" target="1.5" nowarn="true"
22+
debug="true" debuglevel="lines,vars,source">
23+
<classpath refid="project.class.path"/>
24+
</javac>
25+
<copy todir="war/WEB-INF/classes">
26+
<fileset dir="src" excludes="**/*.java"/>
27+
</copy>
28+
</target>
29+
30+
<target name="gwtc" depends="javac" description="GWT compile to JavaScript (production mode)">
31+
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
32+
<classpath>
33+
<pathelement location="src"/>
34+
<path refid="project.class.path"/>
35+
</classpath>
36+
<!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->
37+
<jvmarg value="-Xmx256M"/>
38+
<arg line="-war"/>
39+
<arg value="war"/>
40+
<!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
41+
<arg line="${gwt.args}"/>
42+
<arg value="com.google.gwt.devmodeoptions.DevModeOptions"/>
43+
</java>
44+
</target>
45+
46+
<target name="devmode" depends="javac" description="Run development mode">
47+
<java failonerror="true" fork="true" classname="com.google.gwt.dev.DevMode">
48+
<classpath>
49+
<pathelement location="src"/>
50+
<path refid="project.class.path"/>
51+
</classpath>
52+
<jvmarg value="-Xmx256M"/>
53+
<arg value="-startupUrl"/>
54+
<arg value="DevModeOptions.html"/>
55+
<arg line="-war"/>
56+
<arg value="war"/>
57+
<!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
58+
<arg line="${gwt.args}"/>
59+
<arg value="com.google.devmodeoptions"/>
60+
</java>
61+
</target>
62+
63+
<target name="build" depends="gwtc" description="Build this project">
64+
</target>
65+
66+
<target name="war" depends="build" description="Create a war file">
67+
<zip destfile="DevModeOptions.war" basedir="war"/>
68+
</target>
69+
70+
<target name="clean" depends="clean-prebuilt" description="Cleans this project">
71+
<delete dir="war/WEB-INF/classes" failonerror="false" />
72+
<delete dir="war/DevModeOptions" failonerror="false" />
73+
</target>
74+
75+
<target name="clean-prebuilt" description="Clean the prebuilt copy">
76+
<delete file="../prebuilt/gwt-dev-plugin/DevModeOptions.html" />
77+
<delete dir="../prebuilt/gwt-dev-plugin/DevModeOptions" />
78+
</target>
79+
80+
<target name="prebuilt" depends="build,clean-prebuilt" description="Copy compiled files into
81+
the prebuilt crx directory">
82+
<copy todir="../prebuilt/gwt-dev-plugin/DevModeOptions">
83+
<fileset dir="war/DevModeOptions" excludes="**/*.java"/>
84+
</copy>
85+
<copy todir="../prebuilt/gwt-dev-plugin/">
86+
<fileset dir="war/">
87+
<include name="DevModeOptions.html" />
88+
</fileset>
89+
</copy>
90+
</target>
91+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 0.0.999//EN" "http://google-web-toolkit.googlecode.com/svn/tags/0.0.999/distro-source/core/src/gwt-module.dtd">
3+
<module rename-to='DevModeOptions'>
4+
<!-- Inherit the core Web Toolkit stuff. -->
5+
<inherits name='com.google.gwt.user.User' />
6+
7+
<!-- Specify the app entry point class. -->
8+
<entry-point class='com.google.gwt.devmodeoptions.client.DevModeOptions'/>
9+
10+
<!-- TARGETING WEBKIT ONLY -->
11+
<set-property name='user.agent' value='safari' />
12+
13+
<!-- Specify the paths for translatable code -->
14+
<source path='client'/>
15+
</module>
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
/*
2+
* Copyright 2010 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package com.google.gwt.devmodeoptions.client;
17+
18+
import com.google.gwt.core.client.EntryPoint;
19+
import com.google.gwt.core.client.GWT;
20+
import com.google.gwt.core.client.JavaScriptObject;
21+
import com.google.gwt.core.client.JsArray;
22+
import com.google.gwt.dom.client.StyleInjector;
23+
import com.google.gwt.event.dom.client.ClickEvent;
24+
import com.google.gwt.event.dom.client.ClickHandler;
25+
import com.google.gwt.event.dom.client.KeyCodes;
26+
import com.google.gwt.event.dom.client.KeyPressEvent;
27+
import com.google.gwt.event.dom.client.KeyPressHandler;
28+
import com.google.gwt.uibinder.client.UiBinder;
29+
import com.google.gwt.uibinder.client.UiField;
30+
import com.google.gwt.user.client.Window.Location;
31+
import com.google.gwt.user.client.ui.Button;
32+
import com.google.gwt.user.client.ui.FlexTable;
33+
import com.google.gwt.user.client.ui.Label;
34+
import com.google.gwt.user.client.ui.RadioButton;
35+
import com.google.gwt.user.client.ui.RootLayoutPanel;
36+
import com.google.gwt.user.client.ui.TextBox;
37+
import com.google.gwt.user.client.ui.Widget;
38+
39+
/**
40+
* The options page for configuring the set of hosts permitted to use the GWT
41+
* Developer Plugin.
42+
*/
43+
public class DevModeOptions implements EntryPoint {
44+
45+
interface Binder extends UiBinder<Widget, DevModeOptions> {
46+
}
47+
48+
private static final DevModeOptionsResources bundle = GWT.create(DevModeOptionsResources.class);
49+
50+
@UiField
51+
Button addBtn;
52+
53+
@UiField
54+
Label errorMessage;
55+
56+
@UiField
57+
TextBox hostname;
58+
59+
JsArray<HostEntry> hosts;
60+
61+
@UiField
62+
RadioButton includeNo;
63+
64+
@UiField
65+
RadioButton includeYes;
66+
67+
@UiField
68+
FlexTable savedHosts;
69+
70+
public void onModuleLoad() {
71+
StyleInjector.inject(bundle.css().getText(), true);
72+
RootLayoutPanel.get().add(
73+
GWT.<Binder> create(Binder.class).createAndBindUi(this));
74+
75+
hosts = HostEntryStorage.get().getHostEntries();
76+
77+
addBtn.addClickHandler(new ClickHandler() {
78+
public void onClick(ClickEvent event) {
79+
addHost(HostEntry.create(hostname.getText(), includeYes.getValue()));
80+
}
81+
});
82+
83+
hostname.setFocus(true);
84+
String host = Location.getParameter("host");
85+
if (host != null) {
86+
hostname.setText(host);
87+
}
88+
89+
hostname.addKeyPressHandler(new KeyPressHandler() {
90+
public void onKeyPress(KeyPressEvent event) {
91+
if (event.getCharCode() == KeyCodes.KEY_ENTER) {
92+
addHost(HostEntry.create(hostname.getText(), includeYes.getValue()));
93+
}
94+
}
95+
});
96+
97+
savedHosts.setText(0, 0, "Host");
98+
savedHosts.setText(0, 1, "Include/Exclude");
99+
savedHosts.setText(0, 2, "Remove");
100+
savedHosts.getCellFormatter().addStyleName(0, 0,
101+
bundle.css().savedHostsHeading());
102+
savedHosts.getCellFormatter().addStyleName(0, 0, bundle.css().textCol());
103+
104+
savedHosts.getCellFormatter().addStyleName(0, 1,
105+
bundle.css().savedHostsHeading());
106+
107+
savedHosts.getCellFormatter().addStyleName(0, 2,
108+
bundle.css().savedHostsHeading());
109+
110+
for (int i = 0; i < hosts.length(); i++) {
111+
displayHost(hosts.get(i));
112+
}
113+
}
114+
115+
private void addHost(final HostEntry newHost) {
116+
if (newHost.getUrl().length() == 0) {
117+
return;
118+
}
119+
120+
boolean alreadyExists = false;
121+
for (int i = 0; i < hosts.length() && !alreadyExists; i++) {
122+
if (hosts.get(i).isEqual(newHost)) {
123+
alreadyExists = true;
124+
}
125+
}
126+
127+
if (alreadyExists) {
128+
error("Cannot add duplicate host entry for " + newHost.getUrl());
129+
return;
130+
} else {
131+
hosts.push(newHost);
132+
clearError();
133+
}
134+
HostEntryStorage.get().saveEntries(hosts);
135+
136+
displayHost(newHost);
137+
138+
hostname.setText("");
139+
hostname.setFocus(true);
140+
}
141+
142+
private void clearError() {
143+
errorMessage.setText("");
144+
}
145+
146+
private void displayHost(final HostEntry newHost) {
147+
int numRows = savedHosts.getRowCount();
148+
int col = 0;
149+
savedHosts.insertRow(numRows);
150+
savedHosts.setText(numRows, col++, newHost.getUrl());
151+
savedHosts.setText(numRows, col++, newHost.include() ? "Include"
152+
: "Exclude");
153+
if (newHost.include()) {
154+
savedHosts.getCellFormatter().addStyleName(numRows, 0,
155+
bundle.css().include());
156+
savedHosts.getCellFormatter().addStyleName(numRows, 1,
157+
bundle.css().include());
158+
} else {
159+
savedHosts.getCellFormatter().addStyleName(numRows, 0,
160+
bundle.css().exclude());
161+
savedHosts.getCellFormatter().addStyleName(numRows, 1,
162+
bundle.css().exclude());
163+
}
164+
165+
Button removeHostButton = new Button("x");
166+
removeHostButton.addClickHandler(new ClickHandler() {
167+
public void onClick(ClickEvent event) {
168+
removeHost(newHost);
169+
}
170+
});
171+
savedHosts.setWidget(numRows, col, removeHostButton);
172+
}
173+
174+
private void error(String text) {
175+
errorMessage.setText(text);
176+
}
177+
178+
private void removeHost(HostEntry host) {
179+
JsArray<HostEntry> newHosts = JavaScriptObject.createArray().cast();
180+
for (int index = 0; index < hosts.length(); index++) {
181+
if (hosts.get(index).isEqual(host)) {
182+
savedHosts.removeRow(index + 1);
183+
} else {
184+
newHosts.push(hosts.get(index));
185+
}
186+
}
187+
188+
hosts = newHosts;
189+
HostEntryStorage.get().saveEntries(hosts);
190+
}
191+
192+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!-- Copyright 2010 Google Inc. -->
2+
<!-- Licensed under the Apache License, Version 2.0 (the "License"); you -->
3+
<!-- may not use this file except in compliance with the License. You may -->
4+
<!-- may obtain a copy of the License at -->
5+
<!-- -->
6+
<!-- http://www.apache.org/licenses/LICENSE-2.0 -->
7+
<!-- -->
8+
<!-- Unless required by applicable law or agreed to in writing, software -->
9+
<!-- distributed under the License is distributed on an "AS IS" BASIS, -->
10+
<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -->
11+
<!-- implied. License for the specific language governing permissions and -->
12+
<!-- limitations under the License. -->
13+
14+
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
15+
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
16+
xmlns:g="urn:import:com.google.gwt.user.client.ui">
17+
<ui:with field='res'
18+
type='com.google.gwt.devmodeoptions.client.DevModeOptionsResources' />
19+
<g:HTMLPanel styleName="{res.css.mainPanel}">
20+
<g:VerticalPanel>
21+
<g:HorizontalPanel>
22+
<g:Image resource='{res.gwt64}' styleName="{res.css.logo}" />
23+
<g:HTML>
24+
<h1> GWT Developer Plugin Options </h1>
25+
</g:HTML>
26+
</g:HorizontalPanel>
27+
28+
<g:Label styleName="{res.css.explanation}">
29+
The GWT Developer Plugin will open a TCP/IP connection to an arbitrary
30+
host/port at the request of a web page. To minimize security risks,
31+
by default it will only connect to the local machine. To allow
32+
cross-machine debugging, you can add exceptions here -- include the
33+
exact host name of the web servers you will use for debugging, but
34+
do not include any you do not trust.</g:Label>
35+
36+
<g:Label ui:field="errorMessage" styleName="{res.css.errorMessage}"/>
37+
<g:HorizontalPanel>
38+
<g:TextBox ui:field="hostname" styleName="{res.css.textBox}" />
39+
<g:Button styleName="{res.css.important}" ui:field="addBtn">Add</g:Button>
40+
<g:VerticalPanel>
41+
<g:RadioButton name="include" ui:field="includeYes"
42+
checked="true">Include</g:RadioButton>
43+
<g:RadioButton name="include" ui:field="includeNo">Exclude</g:RadioButton>
44+
</g:VerticalPanel>
45+
</g:HorizontalPanel>
46+
47+
<g:FlexTable ui:field="savedHosts" styleName="{res.css.savedHosts}">
48+
</g:FlexTable>
49+
</g:VerticalPanel>
50+
</g:HTMLPanel>
51+
52+
</ui:UiBinder>

0 commit comments

Comments
 (0)