Now we are going to have to start moving into term papers and academic essays.
First of all, you are moving the goal posts. The original question was, "How do you go about keeping weapons technology from quickly spreading and becoming widespread?" and not, "How do you go about keeping weapons technology from fundamentally overturning the socio-political order and all military paradigms in 400 centuries or less?"
Only if:
1) The nation is interested in expansion
2) The island has enough trees for a vast armada of boats
3) The nation is populous enough to stand against all other nations
Of the three, only #1 really is limiting and I would argue that #1 was assumed by my statement of 'give a technological advantage to an isolated region'. Large continious empires with many neighbors tend to reach a point where they become inward looking and cease expansion. Two doesn't apply because as point of fact, England began importing trees early in its expansion from North America and Russia. In particular, England ran out of trees to build suitable tall masts almost immediately. Spain didn't have enough trees to run its naval empire right from the start, so began importing lumber from the Carribean almost as soon as it figured out it could import gold from there as well. Three doesn't apply because while England did achieve fairly high population density for its size, it was never as densely populated or as populace as the continent to say nothing of its size relative to the population of the empire it carved out. The same was earlier true of the city of Rome and its surrounding Latin speaking region. A small population with a technological advantage can successfully dominate a much much larger one.
China had crude had firearms as early as the 1300s and boat-making technology capable of reaching North America. Yet somehow they failed to take over the entire world. But they didn't because they did not consider the rest of the world as worth conquering.
This is part of the different choices made in the 15th century I mentioned earlier. But again, at this point China was large, with many neighbors, and hardly the isolated region I postulated. Besides, regardless of China's decision to halt expansion (see Rome for parallels right down to the building of walls), this can't be used as an example of not leaknig weapons technology. China invents it, it filters out to the hinterlands, and bam, you have a bunch of formerly backwater kingdoms in Europe conquering not just the known world but the whole world.
Likewise, canons and guns made their way into the European and Arab worlds as early as the 14th century but it took four-hundred years for them to slowly replace and rewrite all the established rules of warfare.
I know what you mean by that, but it is an exageration to suggest that it took 400 years for guns to make a major socio-political or military impact. In half that time, the gun had overturned fuedalism, helped create the moderrn nation state, changed the concept of an army from being a small cadre of elite aristocrats to a mass of plebians, helped usher in a proto-democracy in England, changed the global balance of power, helped launch the European powers into the beginnings of colonialism, and had become the dominate army of both land and naval warfare. By the 16th century, every single aspect of medieval military technology was obselete. The curtain wall had to be replaced by the star fortress. Infantry replaced cavalry as the dominate arm, and the professional mercenary had replaced feudal service. Armor was increasingly obselete on the battlefield, naval actions were increasingly about gunplay rather than boarding actions. The musket was revolutionary from its introduction, and the arquebus and cannon as much nearly so.
The knowledge of black powder could be a "secret recipe" kept hidden by gunsmiths and masters and only taught to apprentices.
And again, this system is not stable as its too much of an advantage to those outside the group to steal the recipe and make it widespread. There must be additional barriers beyond secrecy alone to justify the lack of widespread knowledge.
But yes, with a sufficiently primitive firearms technology, it can exist along side traditionl melee weapons for a considerable period. All of this brings me back to what I said in the first place, "Take away those advantages, make them unreliable, expensive, difficult to use, impossible to stockpile, and really no more lethal than longbows or magic, and they become a marginalized weapon.
I will admit that the Patherfinder RAW makes this job more difficult because they use the mechanic of the 'touch attack', which means that the musket resolves for the average D&D military a very intragient and otherwise difficult problem - "What can you do to make your average soldier effective against monsters that have very high AC, usually as a result of supernaturally strong natural armor?"
Under my preferred rules for firearms, the advantages they produce are not nearly so radical. " That is, the advantages aren't nearly so radical for primitive weapons.
However, there is an additional problem with trying to introduce firearms at a sufficiently low level of technology. With many groups, you'll get metagaming by the players who know that its relevatively easy to lift firearms technology by a couple of decades or centuries and will actively work to do so.